【发布时间】:2014-09-19 10:14:10
【问题描述】:
有没有办法在 IE9 的 ajax 调用中检查与服务器的连接状态?
我在支持 XHR 的浏览器中使用它:
AJS.$.ajax({
url : "path_to_server",
type : 'DELETE',
async:false,
data:JSON.stringify(resquestData)
}).done(function(){
doSomething();
}).fail(function(response,textStatus, xhr){
if(xhr.code == 19){ // where i check if it is a NetworkError
alert("connection lost");
}else{
alert("error");
}
}
);
我的问题是我无法让这个解决方案在 IE9(或更低版本)中运行,因为浏览器不支持 xhr (XmlHttpRequest)。有什么解决办法吗?
最好的问候
[编辑]
我尝试在 ajax 函数之前创建一个 ActiveXobject:
AJS.$("#import").click(function() {
var xmlhttpie;
if (window.ActiveXObject) {
try {
xmlhttpie = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttpie = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
xmlhttpie = false;
}
}
}
AJS.$.ajax({
url : "path_to_server",
type : 'DELETE',
async:false,
data:JSON.stringify(resquestData)
}).done(function(){
doSomething();
}).fail(function(response,textStatus, xhr){
if(xhr.code == 19){ // where i check if it is a NetworkError
alert("connection lost");
}else{
alert("error");
}
}
);
}
但是在 IE9 中调试(在 Ajax 函数内部)时,我得到了这个(其中“A”是 xmlhttpie):
【问题讨论】:
标签: ajax connection xmlhttprequest internet-explorer-9