0

This should be pretty simple, I can't figure out whey my ajax code keeps saying there is an error.

The data sends fine to the server, there are no errors on the server, it returns the expected results, but hits the 'error:' function every time.

Someone please help this is really anoying me :(

var sendData = new Object(), self = this;

    sendData.type = 'get';

    $.ajax({
        type: "GET",
        url: "/Highscores.aspx",
        data: JSON.stringify(sendData),
        dataType: "json",
        success: function (respText) {
            self.renderScores(respText);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert('An error occoured when getting the high scores');
        }
    });
4

3 回答 3

1

只是一个建议..为什么你不尝试使用完成和失败而不是成功,错误。前几天我在玩使用成功,当我使用超时时它不能正常工作。我改为使用 done 并失败,一切正常。

function getPartyIdName(partyId, isPrimary) {
    startDimScreen();
    var url = 'validateParty.html?partyId=' + partyId + '&isPrimary=' + isPrimary;
    $.ajax({url: url, context: document.body, timeout: 10000}).done(
        function (data) {
            stopDimScreen();
            handleResponse(data);
        }
    ).fail(
        function (data, textStatus) {
            if (textStatus) {
                alert("An error has occurred:" + textStatus);
            }
            stopDimScreen();
        }
    );
}
于 2013-05-30T01:52:20.173 回答
0

有时在返回预期结果后,这个错误块也会在某个时候执行。

错误:

function (xhr, ajaxOptions, thrownError) {
      alert('An error occoured when getting the high scores');
}
于 2013-05-30T02:38:17.140 回答
0

好吧,我想我只是我的服务器没有正确返回 JSON。

于 2013-05-30T02:06:28.667 回答