javascript - How to change this ajax code to long polling -
this question exact duplicate of:
this ajax code please can tell me how can change code long polling ?
here code :-
var chat = {} chat.fetchmessages = function () { $.ajax({ url: 'ajax/ajax/chat.php', type: 'post', data: { method: 'fetch' }, success: function(data) { $('#chats').html(data); } }); } chat.interval = setinterval(chat.fetchmessages, 1000);
you have put next call of fetchmessage in callback of previous 1 :
var chat = {} chat.fetchmessages = function () { $.ajax({ url: 'ajax/ajax/chat.php', type: 'post', data: { method: 'fetch' }, success: function(data) { $('#chats').html(data); chat.fetchmessages(); // let's again } }); } chat.fetchmessages(); // first call
Comments
Post a Comment