我试图在每一行上创建一个发送请求的表单,但是setTimeout()似乎无法正常工作 然后我尝试这样
<script> <!-- function kirimRequest() {
var jedamili = document.getElementById('delay').value;
var jeda = jedamili * 1000;
var data = document.getElementById('ids').value;
var jumlah = data.split('\n').length;
var x = 0; if (jedamili != null && jedamili != 0) {
var igniel = setInterval(function rain() { if (x < data) {var xx = data.split('\n')[x];
var token = document.getElementById('token').value;
var hasil = data.join(",");
//console.log(data);
$.getJSON("https://blablabla", {
method: "post",
uids: hasil,
access_token: token
},
function(a) {
console.log(JSON.stringify(a));
})
.done(function(obj,status,xhdr){
$('#right').append("Successful <br />");
setTimeout(function(){
$('#right').text("");
}, 2000);
//$('#out').style.background("yellow");
console.log(hasil);
})
.error(function(){
console.log("Error");
});
}
//--> </script>
<div id="right"></div> <textarea placeholder=" baris 123456789
123456789 123456789 123456789 123456789" id="ids" style="margin:
0px;width: 100%;height: 100px;"></textarea>
我希望每一行的数据都会延迟发送。但它的发送没有延迟
答案 0 :(得分:0)
尝试编写一个可以调用的函数。像这样:
function delay(f, ms) {
return function() {
var savedThis = this;
var savedArgs = arguments;
setTimeout(function() {
f.apply(savedThis, savedArgs);
}, ms);
};