XMLHTTPRequest - 测试连接而不是 .send(null) 失败 [英] XMLHTTPRequest - Test for Connection instead of .send(null) failure
本文介绍了XMLHTTPRequest - 测试连接而不是 .send(null) 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var xml = null;
xml = new XMLHttpRequest();
xml.open("get", who, false);
xml.send(null);
if ((xml.status >= 200 && xml.status <= 300) || xml.status == 304) {
var hi = xml.responseText;
} else {
alert("No Internet Connection! You will have to enter information by hand");
};
我想设置这个警报,如果没有互联网连接,它会这样说.但是,浏览器在 xml.send(null) 处停止/挂起,并带有 NS_ERROR_FAILURE:Failure.如何为连接正确设置测试?
I want set up this alert where if there is no internet connection, it will say so. However, the browser stops/hangs at xml.send(null) with NS_ERROR_FAILURE:Failure. How can set up the test properly for a connection?
推荐答案
试试这个.
function check() {
var z, xml = null;
xml = new XMLHttpRequest();
xml.open("get", who, false);
try {
xml.send(null);
} catch(z) {
alert("Network failure");
return;
}
if ((xml.status >= 200 && xml.status <= 300) || xml.status == 304) {
var hi = xml.responseText;
} else {
alert("No Internet Connection! You will have to enter information by hand");
}
}
这篇关于XMLHTTPRequest - 测试连接而不是 .send(null) 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文