Jquery.get() asynchronous or synchronous?

Asked

Viewed 397 times

3

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

I know it works that way:

$.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 do not know if the default value async is as true or false.

2 answers

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 observe that the value of async, is, by default, true.

  • And if I want to use like false ?

  • Which jQuery version do you use?

  • ,the most recent

  • 1

    With $.get you can only change this behavior with ajaxSetup. (e.g. jQuery.ajaxSetup({async:false});), which is not recommended.

3


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

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

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

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

  • dvd $.get() was removed async false ?

  • 2

    There has never been, there is no way to pass this option in the $.get method..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.