Credit to Todd Gentille at Syncor Systems for the original idea and base. You can find his original example at http://www.netburner.com/support/techni ... ments.html.
This application is simply a webpage that counts up the Ticks that the netburner module has been running. It displays the ticks on the webpage counting up without having to refresh the webpage. This is accomplished by using Ajax in Javascript to query another webpage that calls a NetBurner HTML function to get the Ticks from the board. This other webpage is queried every 5 millisecs. To the code:
main.cpp - Nothing special here, only the web function call:
Code: Select all
void getHTMLTicks(int sock, PCSTR url) {
char tick[40];
siprintf(tick, "%d", TimeTick);
writestring(sock, tick);
}
Code: Select all
<!--FUNCTIONCALL getHTMLTicks -->
Code: Select all
window.onload=function(){
setInterval("processPage()", 20)
}
Code: Select all
function processPage() {
url = 'ticks.html';
// Most browser support
if (window.XMLHttpRequest) req = new XMLHttpRequest();
// IE5, IE6 support
else if (window.ActiveXObject) req = new ActiveXObject("Microsoft.XMLHTTP");
if (req != null) {
req.onreadystatechange = getTicks;
req.open("GET", url, true);
req.send(null);
}
else {
alert("Browser not supported");
}
}
Code: Select all
function getTicks() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("TICK").innerHTML = req.responseText;
}
}
}
Code: Select all
<HTML>
<BODY>
The NetBurner has been up for <span id="TICK"></span> ticks.
</BODY>
</HTML>
Thats it. You can easily modify this source to add seamless updates to your own webpages running off the NetBurner board. Full example is attached to this message
Note: This application does not appear to run correctly in IE8. I have not tested other IE versions. If anyone knows why, id be happy to hear it. To me, it appears IE is caching my function page.