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
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 $.
By default jQuery is not providing synchronous request, so we have to implicitly define synchronous request using $. ajax().
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.
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]);
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.
$.get
is simply a shorthand for:
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With