Jquery.get () as asynchronous or synchronous?

3

I've seen the official documentation here and I do not see that the default value is asynchronous or synchronous, I see no example how to use both (in the second code below).

I know this works:

$.ajax({
  url: url,
  async: false,
  data: data,
  success: success,
  dataType: dataType
});

The following code does not exist async ?

$.get( "test.cgi", { name: "John", time: "2pm" } )
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  });

The second code does not know if the default value async is as true or false .

    
asked by anonymous 10.07.2018 / 01:42

2 answers

3

All Ajax by default is asynchronous . The $.get method is a short form ( shorthand ) of $.ajax that uses the GET method and, because it is short form, the only parameters are, according to the mentioned documentation:

jQuery.get( url [, data ] [, success ] [, dataType ] )
  • URL: page to be requested
  • data: the values to send to the server
  • Function: this function is success if the request was successful
  • dataType: expected data type

There are other callbacks like done , fail , always , each with its function.

If you want to use async: false you will have to use the default method $.ajax . What is neither recommended as explained in this answer .

    
10.07.2018 / 02:03
3

Explanation

Yes, the method $.get is asynchronous, it is an abbreviated form of the code below.

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

According to the method documentation $.ajax , we can see that the value of async , is , by default, true .

    
10.07.2018 / 02:02