前台js调用后台方法,如下:
- JScript code
function tellPoint()
{
var flag=0;
Default2.displayRst(flag,callback);
}
function callback(response)
{
if(response.error) alert('数据传输失败!')
else
{
document.getElementById('TextArea1').value+=response.value+"\n$";
}
}
后台:
- C# code
[AjaxPro.AjaxMethod] public string displayRst(int flag) { …… while(flag==0) { foreach (FileInfo fi in dir.GetFiles()) { if (fi.Name.Substring(fi.Name.LastIndexOf(".") + 1) != "zip") { flag = 1; //显示文件内容 switch (method) { case 1: myResult = this.ReadIni(fi.FullName); break; case 2: myResult = this.ReadSort(fi.FullName); break; case 3: myResult = this.readWebSite(fi.FullName); break; case 4: myResult = this.ReadFile(fi.FullName); break; default: break; } break; } } } return myResult; }
如果后台执行时间短,回调函数就能正常运行,如果超过10s,就进不了回调函数里头,这是什么问题呀?
附注:后台函数的循环是在等待网络传输数据,直到数据传过来之后才结束循环。
------解决方案--------------------
AjaxPro.timeoutPeriod = 1000 * 60 * 60; 毫秒为单位