tags:

views:

194

answers:

2

Hello,

I'm trying to create a chat application with jQuery without having to using setTimeout in order to minify the number of ajax request :

function checkChat(){    
  new jQuery.ajax({
        'url'     : './chat/check.php',
        'cache'   : false,
        'success' : function(messages) {
                      if( messages.length ) {
                       $("#empty_chat").append(messages);
                   //write to chat wall
                 }
                 checkChat();
             }
   });
}

On a simple page that's working great but on page that have others ajax events (like navigation) the request are queued and nothing appear as long as messages is empty.

The cursor is on a waiting state too.

Is there any way to solve this ?

Thanks, Adrien

A: 

Not really, unless you want to look into Comet, you're still going to need to poll for messages and setTimeout is fine.

The recursion you setup there with checkChat() being called recursively should be set to a setTimeout or you'll stack overflow lol

setTimeout(checkChat,2000);

and need to remove the new operator and just do

jQuery.ajax or $.ajax

http://stackoverflow.com/questions/136012/comet-and-jquery

Chad Grant
thanks Deviant, but Comet seem too complex for me =)
adrien334
comet won't solve the request limit issue either
fforw
@fforw there is no mention of request limit in his question. He's trying to avoid polling via ajax
Chad Grant
> On a simple page that's working great but on page that have others ajax events (like navigation) the request are queued and nothing appear as long as messages is empty.
fforw
nothing appears as long as the messages is empty ... which is why he started polling and it works. And from what I read in that,.. he wants to make it faster,
Chad Grant
A: 

The effect of AJAX requests being queued up is most likely due to the limit of active requests to the same domains which is 2 per default on most browsers.

fforw