实现AJAX的基本步骤
2015-01-04 19:59
435 查看
要完整实现一个AJAX异步调用和局部刷新,通常需要以下几个步骤:
(1)创建XMLHttpRequest对象,也就是创建一个异步调用对象. //IE6以上 var xhr= new XMLHttpRequest(); //IE6 var xhr=new ActiveXObject("Microsoft.XMLHTTP") (2)创建一个新的HTTP请求,并指定该HTTP请求的方法、URL及验证信息. xhr.open(方法,url,是否异步) (3)设置响应HTTP请求状态变化的函数. <script type="text/javascript"> function getDoc(){ var xmlhttp; if(window.xmlhttpRequest){ xmlhttp=new XMLHttpRequest(); } else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//for IE6 } xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState==4&&xmlhttp.status==200){ document.getElementById("?myId").innerHTML=xmlhttp.responseText; } } xmlhttp.open("?GET", index.php,true); xmlhttp.send(); } </script> </head> <body> <button type="button" onclick="getDoc()">请求数据</button> </body> (4)发送HTTP请求. xmlhttp.send(); (5)获取异步调用返回的数据. (6)使用JavaScript和DOM实现局部刷新.
相关文章推荐
- 实现AJAX的基本步骤
- 实现AJAX的基本步骤
- 实现AJAX的基本步骤
- 实现Ajax的基本步骤
- 实现AJAX的基本步骤
- 实现AJAX的基本步骤
- AJAX的基本实现步骤
- 实现AJAX的基本步骤
- 原始ajax的基本实现步骤
- ajax 的原理及实现步骤
- 关于Ajax以及开发Ajaxt的基本步骤
- 实现心理声学模型的基本步骤
- Ajax 异步请求的基本步骤
- 运用ajax应用开始时基本实现功能代码
- Java 实现解析xml文件的基本步骤(做笔记)
- Anroid之实现菜单几个基本步骤
- Ajax之实现步骤
- 转:WCF传送二进制流数据基本实现步骤详解
- Ajax的基本步骤
- 利用AjaxControlToolkit实现百度搜索时的下拉列表提示详细步骤