<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Chapter 6 : Networking Considerations - ping</title>
<script src="https://ajaxref.com/ch6/ajaxtcr.js" type="text/javascript">
<script type="text/javascript">
var g_serverup = true;
function sendPingRequest()
{
var url = "https://ajaxref.com/ch6/ping.php";
var options = {method:"HEAD",
onSuccess: handlePingResponse,
onFail: handlePingResponse,
onTimeout: handlePingResponse
};
AjaxTCR.comm.sendRequest(url, options);
}
function handlePingResponse(response)
{
if (response.xhr.status == "200")
g_serverup = true;
else
g_serverup = false;
document.getElementById("statusOutput").innerHTML = "As of " + (new Date()).toLocaleString() + ", the server is " + (g_serverup ? "up" : "down");
}
window.onload = function()
{
sendPingRequest();
g_Timeout = window.setInterval( function(){sendPingRequest();}, 3000);
}
</head>
<body>
<h1>Server Status</h1>
<div id="statusOutput"> </div>
</body>
</html>