JavaScript XMLHttpRequest 对象
来源:互联网 发布:汽车维修软件 编辑:程序博客网 时间:2024/05/20 20:58
XMLHttpRequest 对象用于在后台与服务器交换数据。所有现代的浏览器都支持 XMLHttpRequest 对象。所有现代浏览器 (IE7+、Firefox、Chrome、Safari 以及 Opera) 都内建了 XMLHttpRequest 对象。
XMLHttpRequest 对象是开发者的梦想,因为您能够:
1.在不重新加载页面的情况下更新网页2.在页面已加载后从服务器请求数据3.在页面已加载后从服务器接收数据4.在后台向服务器发送数据
//创建 XMLHttpRequest 对象的语法: var xhr = new XMLHttpRequest();
应用1:
//老版本的 Internet Explorer (IE5 和 IE6)使用 ActiveX 对象:var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
var xmlhttp;function loadXMLDoc(url){xmlhttp=null;if (window.XMLHttpRequest) {// 新浏览器支持,大多浏览器支持 xmlhttp=new XMLHttpRequest(); }else if (window.ActiveXObject) {// IE5 IE6浏览器支持 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change; xmlhttp.open("GET",url,true); xmlhttp.send(null); }else { alert("Your browser does not support XMLHTTP."); }}function state_Change(){if (xmlhttp.readyState==4) {// 4 = "loaded" if (xmlhttp.status==200) {// 200 = OK // ...our code here... } else { alert("Problem retrieving XML data"); } }}
应用2:
function getApplePaySession(url) { return new Promise(function (resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open('POST', '/getApplePaySession'); xhr.onload = function () { if (this.status >= 200 && this.status < 300) { resolve(JSON.parse(xhr.response)); } else { reject({ status: this.status, statusText: xhr.statusText }); } }; xhr.onerror = function () { reject({ status: this.status, statusText: xhr.statusText }); }; xhr.setRequestHeader("Content-Type", "application/json"); xhr.send(JSON.stringify({url: url})); });}
0 0
- JavaScript对象XmlHttpRequest
- Javascript-XMLHttpRequest对象简介
- javascript中XMLHttpRequest对象
- JavaScript XMLHttpRequest 对象
- javascript XMLHttpRequest对象全面剖析
- javascript XMLHttpRequest对象全面剖析
- javascript XMLHttpRequest对象全面剖析
- javascript XMLHttpRequest对象全面剖析
- javascript 之xmlHttpRequest对象_ajax
- javascript XMLHttpRequest对象全面剖析
- ajax的核心javascript对象XMLHttpRequest创建
- javascript对象字面量 与XMLHttpRequest
- JavaScript中XMLHttpRequest对象初步使用
- JavaScript笔记整理 —— XMLHttpRequest对象
- JavaScript XMLHttpRequest
- javascript XMLHttpRequest
- XMLHttpRequest对象
- XMLHttpRequest对象
- Codeforces 2B The least round way
- LDAP网络账户
- bootstrap画板类样式
- GDOI2017总结
- Linux 后台输入命令及后台运行程序 nohup 命令 小结
- JavaScript XMLHttpRequest 对象
- 动态规划专题小结:四边形不等式优化
- 找出连加值最大的子数组
- [Android] EditText设置只能输入2位小数的探讨
- android专题研究--内存泄漏(leakcanary用法与实现原理)
- Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks 代码编译
- Jetson TX1开发笔记(四):使用Caffe对摄像机视频流中的目标进行识别
- hdu1548 A strange lift
- php move_uploaded_file