首页 新闻 会员 周边

setInterval中使用ajax调用WebMethod方法的问题

0
悬赏园豆:30 [待解决问题]

在setInterval中使用ajax访问后台方法RequestProgress,刚开始无法进入RequestProgress中,过了2分钟左右才得到RequestProgress的返回值,也就是60左右,这是什么原因
前台:
function Uploadx() {
var interval = setInterval(function () {
//每次触发事件
$.ajax({
type: "post",//请求方式
async: true,
contentType: "application/json",
url: "DA_Method.aspx/RequestProgress",//发送请求地址
data: "{}",
cache: false,
dataType: "json",//设置返回数据的格式
success: function (data) {
var pos = parseInt(data.d);
top.Dialog.alert(pos);
if (pos >= 100) {
clearInterval(interval);
return;
}
},
//请求出错的处理
error: function () {
clearInterval(interval);
top.Dialog.alert("请求出错2!");
}
});
}, 3000);
$.ajax({
type: "post",//请求方式
async: true,
contentType: "application/json",
url: "DA_Method.aspx/sssss",//发送请求地址
data: "{}",
dataType: "text",//设置返回数据的格式
success: function () {
$("#form1").unmask();
},
//请求出错的处理
error: function (event, xhr, options, exc) {
top.Dialog.alert("请求出错1!");
$("#form1").unmask();
}
});
}
后台:
[WebMethod]
public static string sssss()
{
rate = 0;
for (int i = 0; i < 100; i++)
{
rate++;
Delay(2000);//延时两秒
}
return " ";

    }

    [WebMethod]
    public static string RequestProgress()
    {
        return rate.ToString();
    }
damonxx的主页 damonxx | 初学一级 | 园豆:125
提问于:2019-08-09 15:40
< >
分享
所有回答(1)
0

for循环体中的Delay这个方法使线程运行了200秒。
所以你二百秒后才得到返回结果,这不是很正常的么

轻红 | 园豆:208 (菜鸟二级) | 2019-09-02 18:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册