Convert jQuery ajax function into promise (in ES6)

If you happens to want to convert jQuery’s ajax function into promise style using ES6 promise. Here is an example for you:

utils.js

Then you can use ajaxPostPromise in this way:

app.js

That’s it!

You can apply the same principle in converting other callback-style library into promise!

p.s. If you are looking for native and promise way to call your API, you may also check out fetch.

Share your thoughts