jQuery AJAX Before Version 1.8.0
Prior to jQuery version 1.8.0, the object returned from jQuery $.ajax() contained functions namely success(), error() and complete().
jQuery AJAX After Version 1.8.0
From jQuery 1.8.0 the $.ajax() function returns a jqXHR object that implements the promises interface (done(), fail(), always() etc.....). The success(), error() and complete() functions are now deprecated.
A quick reminder for those learning:
- The .done() method replaces the deprecated jqXHR.success() method.
- The .fail() method replaces the deprecated .error() method.
- The .always() method replaces the deprecated .complete() method.
jQuery AJAX Before Version 1.8.0 Example
$.ajax({
url: 'getname1.html',
dataType: 'html',
success: function (data, textStatus, xhr)
{
console.log(data);
},
error: function (xhr, textStatus, errorThrown)
{
console.log('error: '+textStatus);
}
});
$.ajax({
url: "getname1.html",
cache: false
})
.done(function(data, textStatus, jqXHR)
{
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown)
{
console.log('error: '+textStatus);
});
Tidak ada komentar:
Posting Komentar