Created
June 29, 2017 19:05
-
-
Save btsimonh/af840daf1e222a6969874d711ae80468 to your computer and use it in GitHub Desktop.
webserver tester
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
<html> | |
<head> | |
</head> | |
<body> | |
<p id="poll">0</p> | |
<p id="errors">0</p> | |
<script> | |
var PollCount = 0; | |
var Errors = 0; | |
var pollintervalms = 100; | |
var errintervalms = 100; | |
function myRequest(urlin, idin){ | |
var xmlhttp = new XMLHttpRequest(); | |
var url = urlin + '?' + Errors; | |
var id = idin; | |
xmlhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
setTimeout(function(){myRequest(urlin, id)}, errintervalms); | |
PollCount++; | |
document.getElementById("poll").innerHTML = "Polls:" + PollCount; | |
} | |
}; | |
xmlhttp.onerror = function() { | |
document.getElementById(id).innerHTML = 'error'; | |
// ask again in 5 seconds | |
setTimeout(function(){myRequest(urlin, id)}, errintervalms); | |
Errors++; | |
document.getElementById("errors").innerHTML = "Errors:" + Errors; | |
}; | |
xmlhttp.onabort = function() { | |
document.getElementById(id).innerHTML = 'abort'; | |
// ask again in 5 seconds | |
setTimeout(function(){myRequest(urlin, id)}, errintervalms); | |
Errors++; | |
document.getElementById("errors").innerHTML = "Errors:" + Errors; | |
}; | |
xmlhttp.open("GET", url, true); | |
xmlhttp.send(); | |
} | |
myRequest("/index.html", "id00"); | |
myRequest("/index.html", "id01"); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment