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
  • Select an option

  • Save davidwwu/cb92b5fd60c17c399f0e97f8df327f8f to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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