1function doTheThing() {
2 return new Promise((resolve, reject) => {
3 $.ajax({
4 url: window.location.href,
5 type: 'POST',
6 data: {
7 key: 'value',
8 },
9 success: function (data) {
10 resolve(data)
11 },
12 error: function (error) {
13 reject(error)
14 },
15 })
16 })
17}
1doTheThing()
2 .then((data) => {
3 console.log(data)
4 doSomethingElse()
5 })
6 .catch((error) => {
7 console.log(error)
8 })
1function doTheThing() {
2 $.ajax({
3 url: window.location.href,
4 type: 'POST',
5 data: {
6 key: 'value',
7 },
8 success: function (data) {
9 console.log(data)
10 },
11 error: function (error) {
12 console.log(error)
13 },
14 })
15}