Ajax(Asynchronous JavaScript And XML)
异步JavaScript和XML
index.php:
<script type="text/javascript" src="ajax.js"></script>
<table>
<tr>
<td bgcolor="red"><a href="#" οnclick="action('edf')">的声誉</a></td>
<td>|</td><td bgcolor="yellow"><a href="#">的声誉</a></td>
<td>|</td><td bgcolor="pink"><a href="#">的声誉</a></td>
</tr>
</table>
<div id="div" background="pink"></div>
-----------------------------------------------------<<<<<<<<<<<<< >>>>>>>>>>>>>--------------------------------------------------------------------------------------------------------------------------
ajax.js:
var xmlHttp;
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function action(id){
S_xmlhttprequest();
xmlHttp.open("GET","show.php?id="+id,true); //这并不是具体的操作 而是打开show.php这个文件,读取里面的内容,寻找解决方案
xmlHttp.onreadystatechange = byphp; //js中引用函数直接写函数名
//执行准备就绪的操作
//xmlHttp.onreadystatechange=function(){
// if(xmlHttp.readyState==4){
// //具体的操作
// }
//}
xmlHttp.send(null);
}
function byphp(){
var content = xmlHttp.responseText;// 获取
document.getElementById('div').innerHTML = content; // div 是"标志位的名称" 标志位在哪儿
//内容就显示在哪儿
//通过getElementById将内容显示到前端
}
show.php:
<?
if($id=$_GET['id']){
echo $id;exit();
}
?>