Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Single Page App - Checking connection using XMLHttpRequest
function check() {
var z, xml = null;
xml = new XMLHttpRequest();
// use xmlHttp object shown in the next snippet if you need to support IE6
// xml = new xmlHttp
xml.open("get", url, 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");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment