AJAX before jQuery 1.8 and After

By Sam Deering

Here is a quick note of AJAX before jQuery 1.8 and the newer version. Don’t forget .success() and .error() still supported in jQuery 1.9.1 so it won’t break your old code and plugins you use. I have also drawn up some some New jQuery.ajax() Examples jQuery 1.9+ so check them out!

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(),, and jqXHR.always() instead.

Get HTML using AJAX before jQuery 1.8

    url: 'test.html',
    dataType: 'html',
    success: function (data, textStatus, xhr)
    error: function (xhr, textStatus, errorThrown)
        console.log('error: '+textStatus);

Get HTML using AJAX jQuery 1.8+

// cache: false is used to fetch the latest version

    url: "test.html",
    cache: false
.done(function(data, textStatus, jqXHR)
.fail(function(jqXHR, textStatus, errorThrown)
    console.log('error: '+textStatus);

Mutiple callbacks can be specified for an $.ajax() request. Callback methods .done(), fail(), always(), then.() are all promise methods of the jqXHR object. All these callback methods fire once the $.ajax() process terminates. Promise callbacks are invoked in the order they are registered.

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

  • Greg Milby

    i still do not see .done/.fail used very much
    tbh, i’m not 100% sure there’s an advantage(?)
    maybe there is?

Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.