Skip to content

Instantly share code, notes, and snippets.

@prasanthj
Created December 15, 2014 19:59
Show Gist options
  • Save prasanthj/8ceeef1e3cc5a5dd350d to your computer and use it in GitHub Desktop.
Save prasanthj/8ceeef1e3cc5a5dd350d to your computer and use it in GitHub Desktop.
jQuery test liveness of URL
function testURL(url, retryInterval, maxRetryInterval) {
$.ajax({
url: url,
type: "GET",
timeout: 2000,
success: function(resp) {
console.log(url + " is alive!")
},
error: function(x, t, m) {
if (t == 'timeout') {
console.log("timeout-retry: " + retryInterval)
} else {
console.log("error-retry: " + retryInterval)
}
retryInterval *= 1.5;
setTimeout(function() {
testURL(url, Math.min(retryInterval, maxRetryInterval), 30000)
}, retryInterval);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment