Skip to content

Instantly share code, notes, and snippets.

@pardamike
Last active December 8, 2017 05:32
Show Gist options
  • Save pardamike/2036840219bf79ca87a6e298cb29e0ce to your computer and use it in GitHub Desktop.
Save pardamike/2036840219bf79ca87a6e298cb29e0ce to your computer and use it in GitHub Desktop.
/* Commonly Misused jQuery AJAX Settings: */
// As of jQuery 2.x
$.ajax({
accept: 'json', // Tells the server the format the client accepts back
dataType: 'json', // When set to 'json', will pre-parse the JSON for you
error: function () {
console.log("Oh no we got a 500!"); // Callback for server errors and timeouts/bad responses
},
success: function () {
console.log("We got a 200!"); // Callback for if the function succeeds/response is ok
},
complete: function () {
console.log("Totally done"); // Callback for when request is done, executes after .success and .error, always executes
}
});
// As of jQuery 3.x - .success, .fail, .complete have been deprecated
$.ajax({
fail: function () {
console.log("Oh no we got a 500!"); // Same as .error
},
done: function () {
console.log("We got a 200!"); // Same as .success
},
always: function () {
console.log("Totally done"); // Same as .complete
}
});
// To check jQuery version:
console.log(jQuery().jquery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment