Apr 3
ajax请求如何自定义超时时间,并处理相应的超时事件呢?

对jQuery 来说,超时可以直接设置timeout参数,并在error事件中捕获第二个参数,如果是“timeout”则表明捕获了超时事件,非常清楚。

例子:

$.ajax({

        type: "POST"
,

        contentType: "application/json"
,

        url: "../ws/MyService.asmx/test"
,

        data: '{"email":"'
+email+'"}'
,

        timeout: 30000, //超时时间:30秒


        dataType: 'json'
,

        error: function
(XMLHttpRequest, textStatus, errorThrown){

        //TODO: 处理status, http status code,超时 408


        // 注意:如果发生了错误,错误信息(第二个参数)除了得到null之外,还可能


              //是"timeout", "error", "notmodified" 和 "parsererror"。


        },

        success: function
(result) {

          // TODO: check result


        }

});        
        
另外,error事件返回的第一个参数XMLHttpRequest有一些有用的信息:
Apr 3
webservice默认请求时间是100秒
客户端调用数据量过大的时候往往就连接超时

ProductWs ps = new ProductWs();  
ps.Timeout = 10 * 60 * 1000; //连接超时10分钟  


如果要设置无限制
ps.Timeout = Timeout.Infinite;  
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]