Код: Выделить всё
$filename = "check";
$content = file_get_contents($filename, true);
if($content == 1) { $content = 0; }
else{ $content = 1; }
file_put_contents($filename, $content);
function getPoll()
{
$('#pollo').show();
document.getElementById("poll").innerHTML="

";
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("poll").innerHTML=xmlhttp.responseText;
if(document.getElementById("pollcheck").innerHTML=="")
{
$('#pollo').hide();
}
}
}
xmlhttp.open("GET","/poll/index2.html",true);
xmlhttp.send(null);
}
function checkpoll()
{
if (window.XMLHttpRequest)
{
xml=new XMLHttpRequest();
}
else
{
xml=new ActiveXObject("Microsoft.XMLHTTP");
}
xml.onreadystatechange=function()
{
if (xml.readyState==4 && xml.status==200)
{
check = xml.responseText;
}
}
xml.open("GET","../poll/check",true);
xml.send(null);
}
$(document).ready(function(){
//upon loading the page, get the current poll, and set the initial value of check and pcheck
getPoll();
checkpoll();
pcheck = check;
}
setInterval(function(){
//check the check page every 5 seconds, if check isn't set, set it, if check isn't equal to pcheck, grab the new poll
try{
checkpoll();
if(check == "")
{
checkpoll();
}
if(check != pcheck)
{
getPoll();
pcheck = check;
}
}
catch(Exception){
alert("ERROR, try refreshing");
}
},5000)
< /code>
Теперь это, кажется, работает довольно хорошо, но я знаю, что должен быть лучший метод для проверки изменений на сервере, а затем с вызовами запроса XML каждые x сумма секунды. Кроме того, если запрос XML не удается, иногда он может сломать обновляющий все вместе. http://lodeclaw.ardentforge.net/ Это веб -сайт, на котором в настоящее время работает опрос.
Подробнее здесь: https://stackoverflow.com/questions/180 ... s-occurred