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
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf316d-1438d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf316d-1438d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?