当我在 JavaScript(使用 JQuery)中发送 Ajax 请求时,它有时会引发我无法捕获的内部服务器错误。错误显示在浏览器中。我什至尝试将 ajax 调用包装在 try-catch 块中。如何处理 Ajax 错误?
编辑 这里是我的代码:
$.post('/multi/getGameStatus', function(data) {
if(data && data.game) {
settings.game = data.game;
setStartRacePopupUI.call(this, data);
// remove all racers
removePlayers.call();
for(var i=0;i<settings.game.players.length;i++) {
var player = settings.game.players[i];
var isme = (player.id == settings.playerId);
addPlayer.call(this, player, isme, i);
}
if (settings.game.gameStatus == "OPEN") {
setTimeout(refreshPlayers, refreshPlayersInterval, nextStatus);
} else if(settings.game.gameStatus == "IN_GAME") {
counterToGameStart = data.sts;
gameFllow(nextStatus);
}
}
});
即使我使用错误处理程序,我仍然会在页面上收到 JS 错误