当前位置:首页>开发>正文

ajax如何设置超时时间 如何设置ExtJS Ajax请求的超时设置之timeout属性

2023-07-31 00:11:48 互联网 未知 开发

 ajax如何设置超时时间 如何设置ExtJS Ajax请求的超时设置之timeout属性

ajax如何设置超时时间?

<script type=”text/javascript”>

       function getXMLHttpRequest()
       {
            var xhr = false
            if ( window.XMLHttpRequest )
            {
                xhr = new XMLHttpRequest()
                if ( xhr.overrideMimeType )
                {
                    xhr.overrideMimeType(”text/xml”)
                }
            }else if ( window.ActiveXObject )
            {
                try{
                        xhr = new ActiveXObject(”Msxml2.XMLHTTP”)
                    }catch(e)
                    {
                        try{
                                xhr = new ActiceXObject(”Microsoft.XMLHTTP”)
                            }catch(e)
                            {
                                xhr = false
                            }
                    }
            }

            return xhr
       }

        window.onload = function()
        {
            var _x = getXMLHttpRequest() //获得XMLHttpRequest对象
            if ( !_x ) return false
            _x.open(”get”,http://www.baidu.com,true)
            _x.onreadystatechange = function()
            {
                if ( _x.readyState == 4 && _x.status == 200 )
                {
                    clearTimeout(clearTO) //如果准备状态成功,并且HTTP状态码正确则清除setTimeout
                    alert(”Success”)
                }    
            }
            var cleaeTO = setTimeout(function()  /*重点,在请求发布后开始设置setTimeout,如果请求状态不成功也就是readyState != 4 那么setTimeout将会在5秒后运行,并弹出信息提示,要是请求成功,将会清除该setTimeout*/
            {
                _x.abort() //终止XMLHttpRequest对象
                alert(”系统异常,请您刷新页面或稍后再试….”)
            },50000)
            _x.send(null)
        }
</script>

如何设置ExtJS Ajax请求的超时设置之timeout属性

ExtJS做Ajax请求的时候,默认的相应时间是30秒,如果后来数据查询时间超过30秒,ExtJS就会报错。
这就需要修改ExtJS的超时时间:在js开始时后加
示例代码如下所示:

view sourceprint?
1.Ext.onReady(function() {
2.Ext.BLANK_IMAGE_URL = ../../common/ext3/resources/images/default/s.gif
3.Ext.Ajax.timeout = 180000 //设置请求超时时间(单位毫秒)
4.})

ajax提交数据 怎么设置超时时间

有timeout这个选项的。
$.ajax({
type: "POST",
url: "test.php",
timeout:2000,
error: function(){
alert(6546)
}
})

jquery中ajax超时怎么处理

var ajaxTimeoutTest = $.ajax({
  url:,  //请求的URL
  timeout : 1000, //超时时间设置,单位毫秒
  type : get,  //请求方式,get或post
  data :{},  //请求所传参数,json格式
  dataType:json,//返回的数据格式
  success:function(data){ //请求成功的回调函数
    alert("成功")
  },
  complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    if(status==timeout){//超时,status还有success,error等值的情况
       ajaxTimeoutTest.abort()
       alert("超时")
    }
设置timeout的时间,通过检测complete时status的值判断请求是否超时,如果超时执行响应的操作。

ajax load方法 默认有超时时间吗

默认jquery是没有设置这个时间的,应该是看每个浏览器对XMLHttpRequest对象是否有超时处理
timeout unsigned long
The number of milliseconds a request can take before automatically being terminated. A value of 0 (which is the default) means there is no timeout.
Note: You may not use a timeout for synchronous requests with an owning window.
如果超时了,会触发jquery的ajax中断abort事件。
当然自己可以手动设置时间ajax里有个timeout :毫秒,

jquery post方法超时时间是多少

以下是实现的代码:
$.ajax({
//其他参数已省...
timeout:5000, //超时时间,考虑到网络问题,5秒还是比较合理的
complete:function(XHR,TextStatus){
if(TextStatus==timeout) //超时啦,干点什么呗
}
})

最新文章