ITPub博客

首页 > 应用开发 > > setInterval中使用ajax调用WebMethod方法的问题

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

作者:dav2100 时间:2019-08-09 17:04:18 0 删除 编辑

在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]publicstaticstringRequestProgress(){returnrate.ToString(); }

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4479/viewspace-3167108/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-17

  • 博文量
    176
  • 访问量
    17570