-
-
Save davidwwu/cb92b5fd60c17c399f0e97f8df327f8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wrote an equivalent function using jQuery ajax