Skip to content

Instantly share code, notes, and snippets.

@davidwwu
Forked from jpsilvashy/hostReachable.js
Last active August 18, 2016 20:24
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 davidwwu/cb92b5fd60c17c399f0e97f8df327f8f to your computer and use it in GitHub Desktop.
Save davidwwu/cb92b5fd60c17c399f0e97f8df327f8f to your computer and use it in GitHub Desktop.
if (typeof networkTest === 'undefined') {
var networkTest = {};
(function() {
this.hostReachable = function() {
// Since we are setting the cache ajax option to false, we can take out the Math.random mechanism
let url = '//' + window.location.hostname;
let status;
$.ajax({
type: 'HEAD',
async: false,
cache: false,
url: url
}).done(function(data, textStatus, jqXHR) {
status = jqXHR.status;
}).fail(function(jqXHR, textStatus, errorThrown) {
status = jqXHR.status;
});
if(status >= 200 && status < 300 || status === 304) {
return true;
} else {
return false;
}
}
}).call(networkTest);
}
@davidwwu
Copy link
Author

wrote an equivalent function using jQuery ajax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment