- common method
function getAjaxPromise (url, params){ | |
return new Promise(function(resolve, reject){ | |
$.ajax({ | |
url: url, | |
type: 'post', | |
async: true, | |
contentType: "application/json", | |
data: JSON.stringify(params), | |
success: function(data){ | |
resolve(data); | |
}, | |
error: function(error){ | |
reject(error); | |
} | |
}); | |
}); | |
} |
- call common method
function callCommonPromiseMethod() { | |
var params = {}; | |
var p1 = getAjaxPromise('/report/xx/data', params); | |
p1.then(function (data1) { | |
return getAjaxPromise('/report/xxx/data', data1); | |
}).then(function (data2) { | |
return getAjaxPromise('/report/xxxx/data', data2); | |
}).then(function(data3){ | |
}); | |
} |