无刷新输出

小纸条信息的无刷新输出主要应用是ajax技术;通过ajax技术调用指定的文件查询是否存在新的消息,并且将结果返回,通过div输出ajax中返回的查询结果;代码如下

<script language="javascript">
function show_counts(senders){ //通过show_counts()函数调用指定的文件统计最新信息
xmlhttp=new XMLHttpRequest();  //设置要执行的文件,并设置栏目标识 url='test.php?sender='+senders; // alert(url); // show_couonts.php?sender=tang xmlHttp.open("get",url, true);   xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4){ tet = xmlHttp.responseText; show_counts11.innerHTML=tet; } } xmlHttp.send(null); } </script>

 数据处理代码

<?php include("conn/conn.php");
	$query=mysql_query("select * from tb_mail_box where tb_receiving_person='".$_GET["sender"]."' and tb_mail_type='1'");
	$myrow=mysql_num_rows($query);
	echo $myrow;
?>

显示页面

<script language="javascript">
	// 定时刷新,间隔1000毫秒执行一次show_counts()函数
	setInterval("show_counts('<?php echo $_SESSION["tb_forum_user"];?>')",1000); 
</script>

猜你喜欢

转载自www.cnblogs.com/aten/p/9059618.html