Skip to content

Instantly share code, notes, and snippets.

@brizandrew
Created July 11, 2017 20:25
Show Gist options
  • Save brizandrew/a8645285cb44b105293b535e8d97318d to your computer and use it in GitHub Desktop.
Save brizandrew/a8645285cb44b105293b535e8d97318d to your computer and use it in GitHub Desktop.
Wraps jQuery's ajax implementation inside an ES6 Promise structure.
// This code snippet requires jQuery to be loaded onto the page.
/**
* Wraps jQuery's ajax implementation inside an ES6 Promise structure.
* Source: https://stackoverflow.com/questions/35135110/jquery-ajax-with-es6-promises
* @function ajax
* @param {object} options - The config to pass to the ajax call.
* @return {object} - A Promise object to complete an ajax call.
*/
function ajax(options) {
return new Promise(function (resolve, reject) {
$.ajax(options).done(resolve).fail(reject);
});
}
@alex-exerve
Copy link

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment