I have to parse 30+ objects and post them to a php file. Sometimes I get an error because the rate of the .each function is posting to fast. I tried to fix this by implementing a delay function (like mentioned here: How to add pause between each iteration of jQuery .each()?). This is my code:
$( "#rules_textfield>div" ).each(function( index ) {
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
delay(function(){
$.post( "getdata.php", { 'parameter1': parameter1, 'parameter2': parameter2})
.done(function( data ) {
$("#logs_result").append(data);
});
}, 1000);
});
But it seems only to work for 1 iteration. All the iterations after this are without a delay.