Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 26, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/58b230055e6e0bc7be4b to your computer and use it in GitHub Desktop.
Save devdays/58b230055e6e0bc7be4b to your computer and use it in GitHub Desktop.
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