P
P
paulvales2015-06-04 21:40:01
JavaScript
paulvales, 2015-06-04 21:40:01

After a few iterations ajax -error, what's the problem?

Hello, an AJAX is executed every 15 seconds, after some time an ubderfiend error appears. How to get rid of this error?

function news() {
var msg = $('#formx').serialize();
for(var i = 1; i < 1000; i++) {window.clearInterval(i);}
var newstimer = window.setInterval('news();', 15000);
$('#conn').addClass('progress');
$.ajax({
type: 'POST',
url: '/a/new.php',
data: msg,
success:function(data) {
$('#conn').html(data);
},
complete: function() {
// indicator deactivation
$('#conn').
},
error: function(xhr, str){
alert('An error occurred: ' + xhr.responseCode);
}
});
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Petrov, 2015-06-04
@paulvales

Instead of generating a bunch of delayed calls
needs to be called once
Do you understand that after the first delayed news() call after 15 seconds, this function will be called 2 times, after the next 15 seconds 4 times, and so on exponentially 2 n ?

X
xmoonlight, 2015-06-04
@xmoonlight

try catch

A
Alexander Krupnov, 2015-06-04
@worlddev

var newstimer = window.setInterval(function(){news();}, 15000);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question