Javascript 在promise中获取返回函数值
我使用javascrip和promise 我在写xxxx的地方搜索得到返回值的方法,有没有办法得到它Javascript 在promise中获取返回函数值,javascript,jquery,promise,Javascript,Jquery,Promise,我使用javascrip和promise 我在写xxxx的地方搜索得到返回值的方法,有没有办法得到它 jQuery.ajax({ success: function(data, status, jqXHR){ const promise = requestUpdated(data.poviderId); promise.then(function(data_tt) { return updateAircrafts(data.s
jQuery.ajax({
success: function(data, status, jqXHR){
const promise = requestUpdated(data.poviderId);
promise.then(function(data_tt) {
return updateAircrafts(data.sspId, data.id); //result
}).then(function() {
//xxxx
transForm.deserialize("#form", data);
}).catch(function(error) {
});
},
error: function (jqXHR, status) {
}
});
您需要传入参数才能获得它。此参数将是
然后语句中预先返回的数据:
jQuery.ajax({
success: function(data, status, jqXHR){
const promise = requestUpdated(data.poviderId);
promise.then(function(data_tt) {
return updateAircrafts(data.sspId, data.id); //result
}).then(function(result) {
// console.log(result);
transForm.deserialize("#form", data);
}).catch(function(error) {
});
},
error: function (jqXHR, status) {
}
});
它作为一个参数传递给.then
:类似.then(函数(xxxx){
。与上一个函数中的数据相同。您需要使用jquery.ajax(…)。然后(函数(数据){…})
。在处理承诺时,永远不要传递成功
和错误
回调!不要将回调和承诺混为一谈(这会使错误处理程序成为噩梦)。如果要使用承诺,请使用jQuery.ajax()
返回的承诺,而不是成功回调。