var m_http = null; function $(x) { return document.getElementById(x); } /* ask unit to update an element */ function ajaxUpdater(id, url) { /* ie needs to load an activeX to do http reqests :-( */ if (window.XMLHttpRequest) { /* Mozilla, Safari,...*/ xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { /* IE */ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } /* we use post and not get because it makes the browser refresh and not just use the cach */ xmlhttp.open("GET", url); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if (id != "") { $(id).innerHTML = xmlhttp.responseText; } } } xmlhttp.send(null); } /* send ?f=x after the file name */ function send_key (ev,index) { if (ev.ctrlKey) { command = "f=" + index ; } else { command = "F=" + index ; } ajaxUpdater("", "key.cgi?" + command); /* we want to update the display after we send a key press */ setTimeout ("update_disp();", 500); } /* update display */ function update_disp() { /* to avoid getting the cached page, we ad a time stamp */ disp_file = "text.html?" + (new Date()).getTime(); ajaxUpdater("display", disp_file); } /* set a 10 sec interval updater of display */ function init() { update_disp(); setInterval ("update_disp();", 10000); var ts = new Date().getTime(); SendRequest ("/par.cgi?getp=1&ts=" + ts,GotAnswerOffset, GotErr); } function GotAnswerOffset(data) { console.log ("good data"); console.log (data); document.getElementById('inpOffset').value = eval( data)[0][0]; } function SetValue() { //"/par.cgi?setp="+point+","+val+",1" var url = '/par.cgi?setp=1,' + document.getElementById('inpOffset').value + ',1'; SendRequest (url, null, null); } function GotErr(data) { console.log ("Bad data"); console.log (data); } function SendRequest (url, OnSucess, onFail) { console.log (url); var _http_request = null; var _onfail = onFail; var _OnSucess = OnSucess; if (window.XMLHttpRequest) { _http_request = new XMLHttpRequest(); } else if (window.ActiveXObject) { _http_request = new ActiveXObject("Microsoft.XMLHTTP"); } var HandleAnswer = function() { if (_http_request.readyState == 4) { if (_http_request.status == 200) { if (_OnSucess) { _OnSucess(_http_request.responseText); _http_request.abort(); } } else { if (_onfail) { _onfail(_http_request.responseText); _http_request.abort(); } } } } _http_request.onreadystatechange = HandleAnswer; _http_request.open('GET', url, true); _http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); _http_request.send(); }