jquery ajax timeout含义是设置请求超时时间,不涉及服务器响应时间

本文探讨了AJAX请求中出现访问超时的情况及解决方案。指出通过设置timeout参数可以有效控制请求等待时间,但需注意其对同步与异步请求的影响及不同浏览器间的兼容性问题。

ajax访问超时怎么办?服务器处理时间过长,或网速很慢,服务器返回数据很慢等,于是想到使用timeout设置,网上有类似代码:

经测试:async必须设置为同步ture,timeout才生效;如果设置为异步,则锁住浏览器,禁止一切操作,直到请求有返回结果。

官网说明

  • timeout

    Type: Number

    Set a timeout (in milliseconds) for the request. This will override any global timeout set with $.ajaxSetup(). The timeout period starts at the point the$.ajaxcall is made; if several other requests are in progress and the browser has no connections available, it is possible for a request to time out before it can be sent. In jQuery 1.4.x and below, the XMLHttpRequest object will be in an invalid state if the request times out; accessing any object members may throw an exception. In Firefox 3.0+ only, script and JSONP requests cannot be cancelled by a timeout; the script will run even if it arrives after the timeout period.

 

转载于:https://my.oschina.net/ffwcn/blog/468634

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值