I'll just post this in a thread of its own to make it more clear.
When using longpolling you establish a simulated constant connection to the server
but if i am using the script below for instance it would constantly return new data
and instantly keep refreshing the shoutbox.
It's what i want indeed but how is it any better than just polling from the client?
Since this one returns results all the time, isn't it just restarting the connection all the time anyway?
I am just trying to grasp how to / when to utilize long polling, polling etc.
Cheers
Server
$time = time();
while((time() - $time) < 30)
{
// Query for new data
$data = $shoutboxView->DrawShoutbox($shoutboxHandler->GetShoutboxMessages(),$isLogged);
// if we have new data return it
if(!empty($data))
{
echo $data;
break;
}
usleep(25000);
}
Client
var lpOnComplete = function(response)
{
$("#shoutboxFullWrapper").html(response);
lpStart();
};
var lpStart = function()
{
$.post('AjaxController.php', {}, lpOnComplete, 'html');
};
$(document).ready(lpStart);

New Topic/Question
Reply




MultiQuote


|