I’ve wrote some code in order to parse and display to my html some content from an .xml file that I’ve created.
Here is the code:
<html>
<head>
<script type="text/javascript">
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("variables.xml");
x=xmlDoc.getElementsByTagName("Light1")[0].childNodes[0];
txt=x.nodeValue;
document.write(txt);
</script>
</body>
</html>
This code is working properly, now all I want is to check every x seconds (lets says 1000msec) if the value of the xml has changed. In other ways load the content of the xml every x seconds..
Use the
setInterval()function to run your script every x milliseconds. For 1000 milliseconds, it will look like this: