On the return value of Recursive use of ajax

made with vue, it was originally a double for loop, and the inner layer nested ajax to get the object. Now you need to change the inner for loop to a recursive ajax function, and the result is that the return value arr is the value of undefined,ajax internal arr. Look at the method on the Internet to add return in front of the getProducts function when calling itself is also a result, ask how to solve?


you can use promise.all for this requirement

function getProducts(link, typeId, pageNum, pageMax) {
    const arr = []
    for (let i = pageNum; i < pageMax; iPP) {
        link = `${link}?id=${typeId}&page=${i}`
        arr.push(
            $.ajax({
                url: link,
                type: 'get',
                async: false,
                timeout: 5000,
                dataType: 'json'
            })
        )
    }
    return arr
}
const arr = getProducts('www.baidu.com', 1, 1, 10)
Promise.all(arr).then(function (values) {
    console.log(values)// values
})
Menu