概述,AJAX使用 HTML java script DHTML 和DOM组件组成,实现的效果是使呆板的web表现形式,变成交互性更强的 AJAX形式
重点,掌握核心 创建组件等
一,核心 创建组件
xmlHttp = new XMLHttpRequest(); 很遗憾,这种方法微软的IE是不支持的
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); 微软只能使用这种方法
所以一般情况下,我们要做一个判断
var xmlHttp; function A_xmlHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject('Microsoft.HTTP'); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest; } } 二,用方法声明,打开请求,获取执行结果
1.方法声明
xmlHttp.open('传递方式','地址',是否允许异步传输)
xmlHttp.open("GET","for.php id="+url,true);
2.打开请求状态
xmlHttp.onreadystatechange = 方法名称
xmlHttp.onreadystatechange = byphp;
3.获取执行结果
var 结果名 = xmlHttp.responseText
var byphp100 = xmlHttp.responseText;
实例1,制作初级AJAX程序
xunhuan.php
< $id=$_GET[id]; if ($id) { for ($i=0;$i<10;$i++) { echo $id; } } > ajax.html
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> http://www.w3.org/1999/xhtml">
| o | x | t | v |
var xmlHttp; function A_xmlHttpRequest() { if(window.ActiveXObject) { xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); } if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function funphp100(url) { A_xmlHttpRequest(); xmlHttp.open('GET','xunhuan.php id='+url,true); xmlHttp.onreadystatechange = byphp; xmlHttp.send(null); } function byphp () { var byphp100 = xmlHttp.responseText; document.getElementById('php100').innerHTML = byphp100; }
作者“PHP学习笔记”