Welcome Guest, Not a member yet? Register   Sign In
Infinite long polling

Hello people!

I'm doing some ajax long polling request on a page of my website, when i call this page it launches a new thread asynchronously.

The problem is, when i leave this page, the thread obviously continues its execution, and when i go back to this page, it launches a new one. So my question is, how can a stop the execution of the thread when i leave the page that is executing it ?
I cannot set a timeout since it is a long polling request.

Here is my code :

The javascript in my client view:
$(document).ready( function() {

function connect()
var urlCall = "<?=base_url() ?>operation/reload/";
       url: urlCall,
       dataType: 'json',
       cache   : false,
       success: function(data) {
                 /* doing some stuff */

And the controller "operation" called :
function reload(){
   log_message('debug','reloading table');
   $newValue = $this->user->getValue();
   if($newValue != $currentValue){
    echo json_encode($variable);

Thanks for your help

Maybe you should read up a language before using it!

See: complete

Pardon my ignorance, i don't know what you had in mind or if i made an obvious mistake writing the post but i don't think the problem comes from the ajax part.

Canceling the request will not cancel the php loop.

Here is a similar thread on stackoverflow that might explain my problem better. However i would like to stop my loop whenever the view is not visible.


Theme © iAndrew 2016 - Forum software by © MyBB