let promise = new Promise(function (resolve, reject) {
foo();
});
promise.then(result => {
alert('done')
});
function foo() {
$.ajax({
url: ......,
type: 'get',
dataType: 'json',
data: data,
success: function(data) {
// ....
resolve();
},
error: function(xhr, textStatus, errorThrown) {
// ...
}
}
}
let promise = new Promise(foo);
promise.then(result => {
alert('done')
});
function foo(resolve, reject) {
$.ajax({
url: ......,
type: 'get',
dataType: 'json',
data: data,
success: function(data) {
// ....
resolve(data);
},
error: function(xhr, textStatus, errorThrown) {
// ...
reject(textStatus);
}
}
}
let promise = new Promise(function (resolve, reject) {
$.ajax({
url: ......,
type: 'get',
dataType: 'json',
data: data,
success: function(data) {
// ....
resolve(data);
},
error: function(xhr, textStatus, errorThrown) {
reject(textStatus);
}
}
});
promise.then(result => {
alert('done')
});
let promise = new Promise(function (resolve, reject) {
foo(resolve, reject);
});
promise.then(result => {
alert('done')
});
function foo(resolve, reject) {
$.ajax({
url: ......,
type: 'get',
dataType: 'json',
data: data,
success: function(data) {
// ....
resolve(data);
},
error: function(xhr, textStatus, errorThrown) {
// ...
reject(textStatus);
}
}
}