Skip to content

Instantly share code, notes, and snippets.

@diewland
Last active September 17, 2019 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diewland/29dc7f673c8eb6993673d56ec75c6152 to your computer and use it in GitHub Desktop.
Save diewland/29dc7f673c8eb6993673d56ec75c6152 to your computer and use it in GitHub Desktop.
jQuery ajax json mode
function ajax_json(type, url, data, success_fn, failure_fn){
let ajax_options = {
type: type,
url: url,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
success: function(resp){
success_fn(resp);
},
failure: function(resp) {
if(failure_fn){
failure_fn(resp);
}
else {
alert('Something went wrong');
console.error('<ERROR>', resp);
}
},
};
$.ajax(ajax_options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment