Last active
September 17, 2019 03:35
-
-
Save diewland/29dc7f673c8eb6993673d56ec75c6152 to your computer and use it in GitHub Desktop.
jQuery ajax json mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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