Search code examples
jqueryajaxasynchronousget

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


Solution

  • 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.