2

I have an ajax polling script ( chat ) and it works great but the problem is that it gets request every 1 second so probably i think that long polling will be better so how can i change this normal ajax polling to a long polling ?

and this is my ajax polling code :-

var chat = {}

chat.fetchMessages = function () {
$.ajax({
    url: 'ajax/ajax/chat.php',
    type: 'POST',
    data: { method: 'fetch' },
    success: function(data) {
        $('#chats').html(data);
        $('#chats').scrollTop($('#chats')[0].scrollHeight);
    }
}); 
}

chat.interval = setInterval(chat.fetchMessages, 1000);
chat.fetchMessages();
Yassin
  • 1,049
  • 11
  • 15
  • http://stackoverflow.com/questions/333664/simple-long-polling-example-code – supermasher Apr 05 '13 at 16:24
  • There are only a couple of changes you need to make to your ajax post, (see the link above) - the main thing to understand is that it's your server-side code that is making the decision not to respond to your clients request until there is something useful to return. – supermasher Apr 05 '13 at 16:27
  • thanks for your help but actually i didn't understand what he is saying in other words i got confused but again thanks very much for your help :) – Yassin Apr 05 '13 at 16:28
  • i need a very simple long polling example to understand it because i think it is very difficult to use ! – Yassin Apr 05 '13 at 16:32

0 Answers0