使用XmlHttpRequest对象发送一次ajax请求
2018-02-08 09:41
501 查看
使用XMLHttpRequest object对象发送一次ajax请求
XMLHttpRequest对象中的open方法open(“method”, “URL”[, asyncFlag[, “userName”[, “password”]]])
property | description |
---|---|
method | The HTTP method used to open the connection, such as GET, POST, PUT, HEAD,or PROPFIND. |
URL | The requested URL. |
asyncFlag | A Boolean value indicating whether the call is asynchronous. The default is true. |
userName | The username of your account. |
password | The password used to connect to your account. |
value | description |
---|---|
0 | Uninitialized |
1 | Loading |
2 | Loaded |
3 | Interactive |
4 | Complete |
function createXmlHtttpRequestObj() { var XmlHttpRequestObj = false; if (window.XMLHttpRequest){ XmlHttpRequestObj = new XMLHttpRequest(); //for ie... }else if (window.ActiveXObject){ XmlHttpRequestObj = new ActiveXObject("Microsoft.XMLHTTP"); } return XmlHttpRequestObj; } function getData(url) { var XmlHttpRequestObj = createXmlHtttpRequestObj(); if (XmlHttpRequestObj){ XmlHttpRequestObj.open("GET",url); XmlHttpRequestObj.onreadystatechange = function () { if ((XmlHttpRequestObj.readyState == 4) && (XmlHttpRequestObj.status == 200)){ var responseText = XmlHttpRequestObj.responseText; layer.msg("ajax获取数据: "+ responseText); } }; XmlHttpRequestObj.send(null); }else { layer.msg("您的网站不支持ajax"); } }
相关文章推荐
- Ajax - 使用XMLHttpRequest对象向服务器发送简单请求
- 使用xmlHttprequest 发送异步请求(Ajax核心对象)
- 使用XMLHttpRequest对象向服务器发送简单的请求
- 使用XMLHttpRequest对象向服务器发送简单请求
- Ajax 使用XMLHttpRequest对象发送数据和接收处理XML源代码
- AJAX核心对象-- XMLHttpRequest 对象使用详解 (二)
- 使用xmlhttprequest对象来进行AJAX的异步数据交互
- Ajax-核心对象--XMLHttpRequest 对象使用详解
- AJAX核心对象-- XMLHttpRequest 对象使用详解 (一)
- 10XMLHttpRequest对象的创建,及发送和接收数据
- 使用 XMLHttpRequest 对象
- 使用JavaScript的XMLHttpRequest发送请求
- AJAX中同时发送多个请求XMLHttpRequest对象处理方法
- 使用XmlHttpRequest对象调用Web Services 服务
- AJAX 简介 及 XMLHttpRequest对象的使用方法
- AJAX核心对象-- XMLHttpRequest 对象使用详解 (一)
- 创建XMLHttpRequest对象并向服务器发送请求的方法
- (转)使用 XML HTTP Request 对象
- 全面剖析XMLHttpRequest对象——发送请求
- 利用XMLHttpRequest对象异步发送XML文档