Reputation: 13
am trying to call an ajax function several times to fetch data from my chat table, and appending the data into the div only if there are new messages in that table. my code
(function CallThat() {
$.ajax({
url:'intervalog.php',
method:'POST',
data:{datime:mylmsgt},
success:function(data){
if(data!=5){
$('#intrmylmsgt').load('intrmylmsgt.php');
$('#chatlogs').append(data);
}
}
});
setTimeout(CallThat, 1000);
}());
this works perfect only for 10-15 seconds, after that it starts giving these errors continuously in console (jquery.min.js)
POST http://******/intervalog.php 0 ()
after that page stuck and i have to close that page. I think the problem is continues ajax request without completing the previous requests, any solutions?
Upvotes: 1
Views: 71
Reputation: 175
you should use async: false to make ajax work synchronously
(function CallThat() {
$.ajax({
url:'intervalog.php',
method:'POST',
data:{datime:mylmsgt},
success:function(data){
if(data!=5){
$('#intrmylmsgt').load('intrmylmsgt.php');
$('#chatlogs').append(data);
CallThat()
}
}
});
}());
and check CallThat() function for empty,null responses . if response is coming empty or null then don't call CallThat() next time.
Upvotes: 1