Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Forked from jasonhinkle/ajax.js
Last active September 4, 2020 07:16
Show Gist options
  • Save CodeBrauer/5e9625818015785e35900249eabe7971 to your computer and use it in GitHub Desktop.
Save CodeBrauer/5e9625818015785e35900249eabe7971 to your computer and use it in GitHub Desktop.
jQuery AJAX Snippet
$.ajax({
url: 'api/url',
method: 'POST',
data: {var:'val'},
contentType: "application/json; charset=utf-8",
dataType: 'json'
}).done(function(data, textStatus, jqXHR) {
console.log('done');
}).fail(function(jqXHR, textStatus, errorThrown) {
if (jqXHR.responseJSON) {
console.log('failed with json data');
} else {
console.log('failed with unknown data');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment