使用XMLHttpRequest 实现http 终止请求和超时
来源:互联网 发布:js获取时间的年月日 编辑:程序博客网 时间:2024/05/21 14:04
getXMLHttpRequest : function () { return new XMLHttpRequest(); },var httpGet = function (url, cbSucc, cbFail, options) { var flag = false; var xhr = cc.loader.getXMLHttpRequest(); xhr.open("GET", url); var timedOut = false; var timer = setTimeout(function(){ timedOut = true; xhr.abort(); }, 3000); if (cc.sys.isNative) xhr.setRequestHeader("Accept-Encoding", "gzip,deflate"); var isRaw = false; if (options && options.responseType) { isRaw = true; xhr.responseType = options.responseType; delete options.responseType; } for (var k in options) if (options.hasOwnProperty(k)) xhr.setRequestHeader(k, options[k]); xhr.onreadystatechange = function () { if(timedOut){ return; } clearTimeout(timer); if (xhr.readyState == 4) { if (xhr.status == 200) { if (isRaw) cbSucc(new Uint8Array(xhr.response)); else cbSucc(xhr.responseText); } else { if (!flag) { flag = true; cbFail(xhr.statusText, xhr.responseText); } } } }; xhr.onerror = function () { if (!flag) { flag = true; cbFail(xhr.status, null); } }; xhr.send(); };
阅读全文
0 0
- 使用XMLHttpRequest 实现http 终止请求和超时
- 使用XMLHttpRequest 实现http 终止请求和超时
- XMLHttpRequest实现终止请求和超时
- AJAX http请求 XMLHttpRequest
- 原生js使用xmlhttpRequest实现ajax请求
- 异步和同步http请求超时机制
- HTTP Get和Post请求设置超时
- js使用XMLHttpRequest实现跨域请求 POST请求
- HTTp 请求json 超时
- Ajax概念介绍(同步和异步,XMLHttpRequest 对象,ajax-http请求,MLHttpRequest发送请求,XMLHttpRequest取得响应)
- Js XMLHTTPRequest 实现GET请求提交和返回内容获取
- 使用XMLHTTPRequest和JQuery库实现AJax
- 使用JavaScript和Ajax发出异步请求 XMLHttpRequest
- 使用JS和Ajax发出异步请求,XmlHttpRequest对象详解
- 使用 JSON 实现 HTTP 请求
- 不用xmlhttprequest,实现ajax请求
- http 请求 超时时间设置
- web 会话超时,请求(http请求和ajax异步请求)处理
- ROS --urdf
- OpenSSL生成正确显示中文证书的方法
- D3系列第二弹——绘制柱状图
- mysql之PXC5.7.18集群系列——1. Percona XtraDB Cluster
- mybatis Mapper.xml中parameterType为object类型的处理方式
- 使用XMLHttpRequest 实现http 终止请求和超时
- CentOS服务器上搭建Gitlab安装步骤、中文汉化详细步骤、日常管理以及异常故障排查
- #输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- 1296:近似计算
- Python学习笔记
- Android问题记录
- QtCreator程序的发布:Windows下、Linux下。
- [RK3288][Android6.0] MII/RMII/SMII/GMII/RGMII/SGMII
- response跳转页面前弹出alert提示框分析及常见的弹出框使用