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?
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
and need to remove the new operator and just do
jQuery.ajax or $.ajax
Comet and jQuery