Reputation: 881
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');
}
});
Upvotes: 0
Views: 414
Reputation: 747
Some times After Returning the expected result also this error block will be executed sometime.
error:
function (xhr, ajaxOptions, thrownError) {
alert('An error occoured when getting the high scores');
}
Upvotes: 0
Reputation: 881
Ok think i figured it out was just that my server wasn't returning JSON properly.
Upvotes: 0
Reputation: 11
Just a suggestion.. Why you don't try using done and fail instead of success, error. The other day I was playing around using success and it wasn't working properly when I was using timeout. I change to use done and fail and everything worked fine.
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();
}
);
}
Upvotes: 1