首页 > 解决方案 > 在ajax(请求)中循环仅第一个结果有效

问题描述

我不明白为什么 ajax 循环只在第一个结果上以及如何修复它?

   arrayOfMatches.forEach((matchesOfElement) => {
                var query = {
                    platformId: matchesOfElement.platformId,
                    gameId: matchesOfElement.gameId,
                    champion: matchesOfElement.champion,
                    queue: matchesOfElement.queue,
                    season: matchesOfElement.season,
                    timestamp: matchesOfElement.season,
                    role: matchesOfElement.role,
                    lane: matchesOfElement.lane,
                    summonerName: summoner.name,
                    summonerAccountId: summoner.accountId,
                }
                $.ajax({
                    url: 'matches.php',
                    method: 'POST',
                    data: query,
                    success: function(data) {
                        console.log(data);
                    },
                    error: function(response, xhr, statusText) {
                        console.log(response);
                    },
                });
            });
        }

唯一的唯一值是“gameId”

提前致谢!

标签: javascriptajaxloopsrequest

解决方案


推荐阅读