автообновление данных в реальном времени
Добрый день! Рисую график с онлайн-доступом, обновление сделал через
setInterval <!DOCTYPE html/> <head> <title>html5 canvas</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> </head> <body> <canvas id="Canvas" width="800" height="600" style="border: 1px solid black"></canvas> <script>
var canv = document.getElementById("Canvas");
var cont = canv.getContext("2d");
window.onload = draw();
setInterval(draw,2000);
function draw() {
var c = file_get_contents("data.txt");
var Data = c.split(",");
cont.fillStyle="#eee";
cont.fillRect(0,0,800,600);
cont.beginPath();
cont.moveTo(0,300);
cont.fillStyle="#000";
cont.lineWidth = 0.5;
var x = 0;
for (i in Data) {
var y = 300 - Data[i];
cont.lineTo(x,y);
cont.fillRect(x-2,y-2,4,4);
x += 10;
}
cont.stroke();
}
function file_get_contents(url) {
var req = null;
try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {
try {req = new XMLHttpRequest();} catch(e) {}
}
}
if (req == null) throw new Error('XMLHttpRequest not supported');
req.open("GET", url, false);
req.send(null);
return req.responseText;
}
</script> </body> возможно ли сделать обновление по событию изменения файла data.txt на сайте, без клиентского запроса? |
| Часовой пояс GMT +3, время: 06:59. |