Promise about solving the problem of ajax nesting

function getPromise(url, method = "GET", data = {}, header = {}) {
    return new Promise((resolve, reject) => {
        wx.request({
            url: url,
            header: header,
            success: function (res) {
                resolve(res)
            },
            fail: function (res) {
                reject(res)
            },
            method: method,
            data: data,
            dataType: "json"
        })
    })
}

is encapsulated as above;
is called as follows

getPromise(_url, "POST", _data)
        .then((res) => {

        })

is called as above, but what if multiple requests are nested within each other?

getPromise(_url, "POST", _data)
        .then((res) => {
            getPromise(_url, "POST", _data)
                .then((res) => {
                               ...
                })
        })
Mar.28,2021

multiple requests to return the Promise object

  

async is used with await

Menu