I’m using jQuery 1.8 and I have an ajax call that returns JSON. If there’s an error, it only returns { "status": "there was an error" } otherwise, it returns a document which is the data that the ajax request means to load which will look something like { "document": { ... } }
On Firefox and Chrome the following code works, but on IE8 I’m getting an error saying data.status is null or not an object (when the URL requested clearly does return a document and not just a status) which then causes the script to crash. Does anybody know how to get around this error message on IE8?
$.ajax({
url: "GanttLoader.ashx?action=loadGantt&gantt=" + current_selected_gantt + "&userId=" + userId,
context: document.body,
type: "GET",
dataType: "json",
success: function (data) {
if (data.status != null) {
if (data.status == "none") {
alert("no gantts found when attempted to load");
} else if (data.status == "locked") {
alert("this gantt is locked");
}
} else if (data.document != null) {
/* process the gantt */
}
},
error: function () {
alert("couldn't load gantt charts");
}
});
The JSON response was actually not sending nothing because in IE8
userIdwas null, breaking my .ashx handler. Because my cookie parsing code (not shown) worked on Chrome / FF but not on IE I thought it the url was being entered correctly. I moved to the jquery cookie plugin and the problem was resolved (why is cookie parsing and setting not standard in jQuery?). Thanks for all of your help even though it was a mistake on my part.