Answer the question
In order to leave comments, you need to log in
Why doesn't data arrive instantly in Comet (Long-Polling)?
I can't immediately receive new data - they come only after a new execution of the getmess function, which is executed when the timer expires, what could be the error?
function getmess(){
$.ajax({
url:"get_mess.php",
type:"POST",
data:{"id":id},
cahce:false,
timeout:30000,
async:true,
success:function( result){
$("#response").html(result);
setTimeout('getmess()',10000);
}
});
}
on the server:
while(true){
$a=$_POST["id"];
$find_mess=(mysql_query("SELECT * FROM saymon WHERE id> '$a' "));
if (mysql_num_rows($find_mess)) {
while($row=mysql_fetch_array($find_mess)){
echo $row['mess']."";
}
flush();
exit;
}
sleep(5);
}
mysql_close();
Answer the question
In order to leave comments, you need to log in
Well, you have setTimeout with an interval of 10 seconds + another sleep 5 seconds, of course, the data will not come instantly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question