Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在promise中获取返回函数值_Javascript_Jquery_Promise - Fatal编程技术网

Javascript 在promise中获取返回函数值

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

我使用javascrip和promise

我在写xxxx的地方搜索得到返回值的方法,有没有办法得到它

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()
返回的承诺,而不是成功回调。