Created
July 11, 2017 20:25
-
-
Save brizandrew/a8645285cb44b105293b535e8d97318d to your computer and use it in GitHub Desktop.
Wraps jQuery's ajax implementation inside an ES6 Promise structure.
This file contains hidden or 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
// 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); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.