为什么setInterval 只执行了一次
1个回答
展开全部
$(document).ready(function () {
var i = 9;
iCount = setInterval(function(){
if(!i)clearInterval(iCount);
startRequest();
i--;
},2000);
});
function startRequest() {
$.ajax({
type: "POST",
url: "test",
dataType: "text",
contentType: "application/json; charset=utf-8",
beforeSend: function (XMLHttpRequest) {
},
success: function (msg) {
if(msg != ''){
clearInterval(iCount);
$("#data").text('');
$("#data").append(msg);
}
}
});
}
-
var i = 9;
iCount = setInterval(function(){
if(!i)clearInterval(iCount);
startRequest();
i--;
},2000);
});
function startRequest() {
$.ajax({
type: "POST",
url: "test",
dataType: "text",
contentType: "application/json; charset=utf-8",
beforeSend: function (XMLHttpRequest) {
},
success: function (msg) {
if(msg != ''){
clearInterval(iCount);
$("#data").text('');
$("#data").append(msg);
}
}
});
}
-
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询