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)
},
})
})
}
doTheThing()
.then((data) => {
console.log(data)
doSomethingElse()
})
.catch((error) => {
console.log(error)
})
function doTheThing() {
$.ajax({
url: window.location.href,
type: 'POST',
data: {
key: 'value',
},
success: function (data) {
console.log(data)
},
error: function (error) {
console.log(error)
},
})
}
doTheThing()
doSomethingElse()