I'm work on script that will send ajax post to another page, i need to make two for loops before send ajax request with time out, one of them send successcfully but when make another loop it send all requests same time and make the server down:(我正在处理将ajax发布发送到另一页的脚本,我需要在超时之前发送ajax请求之前进行两个for循环,其中一个成功发送,但是在进行另一个循环时它将同时发送所有请求并使服务器下:)
$("#me").on("click", function (event) {
event.preventDefault();
var lines = $('#emails').val().split('
');
var sendToServer = function(lines, index){
item = lines[index];
if (item.trim().length != 0){
for(idd = 1; idd <= 100; idd++){
$.ajax({
type: 'POST',
url: 'inc/save.php',
data: { users : lines[index] , id : idd },
success: function(msg){
$('#result').append(msg);
if (index < lines.length) {
setTimeout(
function () { sendToServer(lines, index+1); },
5000 // delay in ms
);
}
}
});
}
}
else { sendToServer(lines, index+1); }
};
sendToServer(lines, 0);
});
ask by Mohamed Aldanaf translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…