运用 Ajax技术 实现一个局部刷新显示的小例子

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();
	}
?>









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值