This was tested on Internet Explorer 10, but set in in a way that runs like IE8
I have two ajax calls. The first one asynchronous and the second one is synchronous. In the first one, I get data from the days of a month. On success, it fires the synchronous ajax call in order to get the holidays.
$(function () {
/*some code*/
Load();
}
function Load() {
/* Some irrelevant code */
var today = new Date();
var selectedDate = (today.getMonth() + 1) + "/" + today.getFullYear();
//PopUp that appears when the Ajax calls are made.
var $waitDialog = $('<div id="waitingPopUp"></div>'); //I shortened the content of this variable.
$waitDialog.dialog({
zIndex: 3000,
title: 'Processing...',
dialogClass: "no-close",
resizable: false,
draggable: false,
modal: true,
closeOnEscape: false
});
ajaxGetMonthRecord(selectedDate);
}
function ajaxGetMonthRecord(selectedDate) {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: url + "/GetMonthData",
data: { 'monthRecord': selectedDate },
dataType: "json",
success: function (data) {
var holidays = ajaxGetHolidays(selectedDate);
createCalendar(data, selectedDate, holidays);
}
},
error: function (jqXhr, textStatus, errorThrown) {
alert("ERROR ON AJAX CALL N°1");
}
});
}
[Back-end function] (this works perfectly):
[OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
public List<MonthData> GetMonthData(string monthRecord)
{
var date = monthRecord.Split('/');
var list = (new MonthData()).GetAll(Convert.ToInt32(date[0]), Convert.ToInt32(date[1])).ToList();
return list;
}
And here is when it fails:
function ajaxGetHolidays(selectedDate) {
var holidays;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: url + "/GetHolidays",
data: { 'monthRecord': selectedDate },
dataType: "json",
async: false,
success: function (data) {
holidays = data;
},
error: function (jqXhr, textStatus, errorThrown) {
alert("ERROR ON AJAX CALL N°2");
}
});
return holidays;
}
[The Back-end function for the 2nd AJAX call]:
[OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
//This function starts running in a loop and never returns the List to the Ajax Call N°2
public List<Holiday> GetHolidays(string monthRecord)
{
var date = monthRecord.Split('/');
var list = (new Holiday()).GetAll(Convert.ToInt32(date[0]), Convert.ToInt32(date[1])).ToList();
return list;
}
When the second ajax call is set as async: false
, the back-end function fires and returns the data. But when it reaches the end of the back-end function, it's fired again, and again, on a continuous loop until the ajax call throws an error.
This is the error information that returns the AJAX call.
readyState: 0
textStatus: "error"
errorThrown:
ABORT_ERR 20
code 19
DATA_CLONE_ERR 25
DOMSTRING_SIZE_ERR 2
HIERARCHY_REQUEST_ERR 3
INDEX_SIZE_ERR 1
INUSE_ATTRIBUTE_ERR 10
INVALID_ACCESS_ERR 15
INVALID_CHARACTER_ERR 5
INVALID_MODIFICATION_ERR 13
INVALID_NODE_TYPE_ERR 24
INVALID_STATE_ERR 11
message "NetworkError"
name "NetworkError"
NAMESPACE_ERR 14
NETWORK_ERR 19
NO_DATA_ALLOWED_ERR 6
NO_MODIFICATION_ALLOWED_ERR 7
NOT_FOUND_ERR 8
NOT_SUPPORTED_ERR 9
PARSE_ERR 81
QUOTA_EXCEEDED_ERR 22
SECURITY_ERR 18
SERIALIZE_ERR 82
SYNTAX_ERR 12
TIMEOUT_ERR 23
TYPE_MISMATCH_ERR 17
URL_MISMATCH_ERR 21
VALIDATION_ERR 16
WRONG_DOCUMENT_ERR 4
But when I set async: true,
it either does the back-end function loop and throws an error with responseText:""
and errorThrown:""
, and also the console throws the following:
XMLHttpRequest: Network Error 0x2f78, Could not complete the operation due to error 00002f78.
Or the back-end function is never fired and returns null on success (though this may be because the asynchronous call haven't finished yet) and the console doesn't catch anything funny.
I tried to set the troubling ajax call before the one that works, but the issue persists. What am I doing wrong and what can I do to fix this?
By the way, I found this on my google search, saying that two Ajax calls can't be made in IE because one aborts the other (from what I understood). Does anyone know about this issue?
Thanks in advance.