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();