Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is $.get of jquery asynchronous?

I was wondering whether I should use asynchronous calls on my website or not. I know to specify this explicitly I need to use

$.ajax

however initially I tried using $.get and although the server had to return lots of information, my browser didn't stuck and I could navigate without any problems.

I searched a little bit online about it, however I'm still not 100% certain about the difference between the two.

If $.get is asynchronous then what's the point of $.ajax? And if it's not, then again seeing how I had no navigation problems with $.get, what's the point of using $.ajax?

thanks in advance

like image 990
ksm001 Avatar asked Dec 02 '12 17:12

ksm001


People also ask

Is get () asynchronous?

get is asynchronous then what's the point of $. ajax ? And if it's not, then again seeing how I had no navigation problems with $.

Is jQuery synchronous or asynchronous?

By default jQuery is not providing synchronous request, so we have to implicitly define synchronous request using $. ajax().

Is jQuery asynchronous?

You can use jQuery to support both synchronous and asynchronous code, with the `$. when` function, and your code doesn't have to care whether or not it's async.

Is jQuery POST asynchronous?

The jQuery post() method sends asynchronous http POST request to the server to submit the data to the server and get the response. Syntax: $. post(url,[data],[callback],[type]);


2 Answers

Yes, $.get is asynchronous. From the documentation:

This is a shorthand Ajax function, which is equivalent to:

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

...and as that doesn't have the async option, async defaults to true. (Note that async will be going away entirely in a future version of jQuery; it will always be true.)

If $.get is asynchronous then what's the point of $.ajax?

$.ajax gives you control over lot more options. $.get is just a shortcut.

like image 116
T.J. Crowder Avatar answered Jan 03 '23 10:01

T.J. Crowder


$.get is simply a shorthand for:

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});
like image 36
João Silva Avatar answered Jan 03 '23 11:01

João Silva