Skip to content

Instantly share code, notes, and snippets.

@osw4l
Created August 10, 2017 15:00
Show Gist options
  • Save osw4l/a22b73eb5fd59f16fc303b52c76e56b9 to your computer and use it in GitHub Desktop.
Save osw4l/a22b73eb5fd59f16fc303b52c76e56b9 to your computer and use it in GitHub Desktop.
function ajax(options) {
return new Promise(function (resolve, reject) {
$.ajax(options).done(resolve).fail(reject);
});
}
then run:
ajax({
url: YOUR_URL,
type: 'post',
dataType: 'json',
data: {
action: some_action,
action_2: another_action
}
}).then(
function fulfillHandler(data) {
// callback
}
).catch(function errorHandler(error) {
// error
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment