Recently, I've been working on a Javascript code that pings Google every 10 seconds and displays the connection status in an HTML MonitorInformation element. However, whenever I try to debug the HTML file, the information displayed is always stuck at "Connecting...wait". I've spent some time trying to troubleshoot this issue but haven't been able to figure it out. Any thoughts on what might be going wrong with my code?
Below are the snippets of my HTML and Javascript code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Monitor.js" type="text/javascript"></script>
<title>Web Site Monitor</title>
</head>
<body onload="setup()">
<div id="MonitorInformation">Connecting...wait</div>
</body>
</html>
Javascript code excerpt:
function setup() {
window.setInterval(PingWebSite, (10 * 1000));
}
function PingWebSite() {
conObj = new ActiveXObject("Msxml2.XMLHTTP");
//...
}
After reviewing, I made some modifications using JSON, as shown below:
function setup() {
window.setInterval(PingWebSite, (10 * 1000));
}
function PingWebSite() {
var http_request = new XMLHttpRequest();
//...
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="Monitor.js" type="text/javascript"></script>
<title>Web Site Monitor</title>
</head>
<body onload="setup()">
<div id="MonitorInformation">Connecting...wait</div>
</body>
</html>
If you have any insights or suggestions, please feel free to share them.