<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
史上最简单之ajax实例
/*
Ajax.js
ajax核心文件
*/
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
function ajax(qurl,showid)
{
//IE7.firefox
xmlHttp.open("GET",qurl,true);
//相应处理函数数的含参写法
xmlHttp.onreadystatechange = function(){handleRequest(showid)};
xmlHttp.send(null);
}
// handleRequest被调用四次
function handleRequest(showid)
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
document.getElementById(showid).innerHTML = xmlHttp.responseText;
}
}
else
{
alert(xmlHttp.readyState);
}
}
/*
Index.htm
*/
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src= ajax.js type=text/javascript></script>
</head>
<body>
<a href=test.php οnclick="ajax(this.href,'test');event.returnValue = false;">asdffa</a>
<div id='test'>
</div>
</body>
</html>
/*
Test.php
服务器相应
*/
<?php
//header不加,中文会出现乱码
header('Content-Type:text/html;charset=GB2312');
echo "<I>史上最简单之AJAX实例</I>";
?>