Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks will be deprecated in jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
I am currently coding as below:
$.ajax({
url: '...',
success: function(){
alert('AJAX successful');
}
});
I am planning to use jQuery 1.8+
Should I just change the success key into done as:
$.ajax({
url: '...',
done: function(){
alert('AJAX successful');
}
});
?
For instance, if you have any of these:
$.ajax({url: '...'}).success(function(){
alert('AJAX successful');
});
$.ajax({url: '...'}).error(function(){
alert('AJAX ERROR');
});
$.ajax({url: '...'}).complete(function(){
alert('AJAX complete');
});
You would have to change it to:
$.ajax({url: '...'}).done(function(){
alert('AJAX successful');
});
$.ajax({url: '...'}).fail(function(){
alert('AJAX ERROR');
});
$.ajax({url: '...'}).always(function(){
alert('AJAX complete');
});
I know this is an old question, and jQuery 1.8 came out ages ago - but to help Googlers like me who are upgrading ancient applications to 3.0, I thought I'd chime in for clarification.
This is valid in versions jQuery 1.8+:
$.ajax({
url: "/api/endpoint",
type: "POST",
data: myData,
success: function(json){
console.log("success");
console.log(json);
},
error: function(jqxhr){
console.log("failure");
console.log(jqxhr.responseText);
}
});
This is NOT valid in versions jQuery 1.8+. It has been removed in 3.0:
var promise = $.ajax({
url: "/api/endpoint",
data: myData,
method: "POST"
});
promise.success(function(json){
console.log("function not defined!"); // same for .error and .complete
});
See @DevIshOne's answer or the jQuery AJAX documentation for how to account for this. You simply have to rename to done(), fail(), and always() respectively, or rewrite the code as per my first code block.
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