亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to return data obtained asynchronously
我想大聲告訴你
我想大聲告訴你 2017-05-16 13:12:20
0
3
526

As shown in the figure, the data is obtained asynchronously using ajax. How to return the data to the previous layer. . . As shown in the figure, how can we make the second return value asynchronously obtain the returned data

我想大聲告訴你
我想大聲告訴你

reply all(3)
僅有的幸福

The person above is right, use promise

get:function(){
    return new Promise(function(resolve,reject){
        //ajax...
        $.post("test.php",function(response){
            resolve(response)
        })
        //如果有錯的話就reject
    })
}

Use

get().then(function(response){
    //response
}).catch(function(err){
    //錯誤處理
})
Peter_Zhu

Either change it to synchronous or use callback, your return is useless

get:function(callback){
    $.post(.....,function(res){
        callback(res)
    })
}

get(function(res){
    console.log(res);
})
Ty80

Make it a Promise

return Promise.resolve($.post(url,data));
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template