paulvales2015-06-04 21:40:01
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);
type: 'POST',
url: '/a/new.php',
data: msg,
success:function(data) {
complete: function() {
// indicator deactivation
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)
Evgeny Petrov, 2015-06-04

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 ?

xmoonlight, 2015-06-04

try catch

Alexander Krupnov, 2015-06-04

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