My current code. But when I load another page, timers does not stop. What I need is refreshing messages and dialogues when user is on the messages.php My current code. But when I load another page, timers does not stop. What I need is refreshing messages and dialogues when user is on the messages.php My current code. But when I load another page, timers does not stop. What I need is refreshing messages and dialogues when user is on the messages.php
function get_page(link){
$jQuery("body").scrollTop(0);
$jQuery.ajax({
type: "POST",
cache: false,
async: false,
url: link,
data: "norefresh=1",
success: function(data){
window.history.pushState("", "", link);
$jQuery("div.content").html(data);
clearInterval(messagesref);
clearInterval(dialoguesref);
if(link.indexOf("messages.php")>=0){
var messagesref = setInterval(function(){
var link = window.location.href;
var href = 'action/get'+link.substr(link.indexOf("messages.php"),30);
var lmid = $jQuery('div.message').last().attr('id');
$jQuery.ajax({
type: "POST",
url: href,
dataType: 'json',
data: 'lmid='+lmid,
success: function(response){
$jQuery.each(response, function(i,message) {
if(!$jQuery('#'+message.id).length){
if(message.from){var mside='right i';}else{var mside='left';};
$jQuery('div.messages').append('<div id="'+message.id+'" class="message '+mside+'" title="'+message.date+'">'+message.text+'</div>').scrollTop(10000);
};
});
}
});
},1000)
var dialoguesref = setInterval(function(){
var link = window.location.href;
var link = link.replace("messages","action/getdialogues");
$jQuery.ajax({
type: "GET",
cache: false,
async: false,
url: link,
data: 'q='+$jQuery('div.messages_users>input[type=text]').val(),
success: function(data){
$jQuery('div#dialogues').html(data);
},
error: function(data){
}
});
},5000)
}
}
});
};