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");
};
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?
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");
};
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?
Share Improve this question asked Oct 14, 2012 at 5:39 dmandman 11.1k25 gold badges116 silver badges217 bronze badges 1- you want to test internet connection or connection to webserver ? you should make any request to webserver if you want to check if connection is here, – zb' Commented Oct 14, 2012 at 5:49
1 Answer
Reset to default 6Try this instead.
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");
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745223504a4617354.html
评论列表(0条)