js return promise with ajax code example
Example 1: javascript promise with ajax
function doTheThing() {
return new Promise((resolve, reject) => {
$.ajax({
url: window.location.href,
type: 'POST',
data: {
key: 'value',
},
success: function (data) {
resolve(data)
},
error: function (error) {
reject(error)
},
})
})
}
Example 2: javascript promise with ajax
doTheThing()
doSomethingElse()