Skip to content

Instantly share code, notes, and snippets.

@DNA

DNA/healthcheck.html

Created Oct 20, 2017
Embed
What would you like to do?
check if url is available
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
let xhr = new XMLHttpRequest();
let serverStatus = document.getElementById('serverStatus');
xhr.open('HEAD', 'https://api.github.com/');
xhr.timeout = 2000;
xhr.onload = _ => serverStatus.innerText = 'ONLINE';
xhr.onerror = _ => serverStatus.innerText = 'OFFLINE';
xhr.ontimeout = _ => serverStatus.innerText = 'OFFLINE';
xhr.send();
}
};
</script>
</head>
<body>
Server status: <span id="serverStatus">checking...</span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment