亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Promise.all([a(),b()]).then(c())無法保證a()和b()中的

使用Promise.all([a(),b()]).then(c())無法保證a()和b()中的

HUX布斯 2019-02-14 15:11:41
異步獲取兩個數據,并在執行完后更新前臺渲染,但現在數據還沒獲取到最后的函數已經執行,代碼如下function a(e) {    if (e) {        $.ajax({            url: '../../a.ashx',            data: { },            type: 'get',            success: function (data) {                console.log(a);            }        })    } else {    }}function b(e) {    if (e) {        $.ajax({            url: '../../b.ashx',            data: {},            type: 'get',            success: function (data) {                console.log(b);            }        })    } else {    }}function c(){    console.log(1);}Promise.all([GetTimes(), GetPackage()]).then(c());執行結果類似這樣:1ab求解。
查看完整描述

1 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

function a() {

    return new Promise(res,rej){

        if(e) {

            $.ajax({

                url: '../../a.ashx',

                data: { },

                type: 'get',

                success: function (data) {

                    res(data)

                }

            })

        }

    }

}


function b() {

    return new Promise(res,rej){

        if(e) {

            $.ajax({

                url: '../../b.ashx',

                data: { },

                type: 'get',

                success: function (data) {

                    res(data)

                }

            })

        }

    }

}

function c(){

    console.log(1);

}

Promise.all([a(), b()]).then(c());


查看完整回答
反對 回復 2019-02-17
  • 1 回答
  • 0 關注
  • 352 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號