我正在使用 jQuery 1.8,并且我有一个返回 JSON 的 ajax 调用。如果有错误,它只会返回{ "status": "there was an error" }
,否则它会返回一个文档,该文档是 ajax 请求意味着要加载的数据,看起来像{ "document": { ... } }
在 Firefox 和 Chrome 上,以下代码有效,但在 IE8 上,我收到一条错误消息data.status is null or not an object
(当请求的 URL 明确返回文档而不仅仅是状态时),这会导致脚本崩溃。有人知道如何绕过 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");
}
});