就是因为我做的第一个例子都运行不出效果,看其他的参考书的例子也一样,结果都无法运行出效果。但是我现在想学学,因此问问<html>
<head>
<title>例子</title>
</head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312"/>
<script language=javascript>
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
xmlhttp=new XMLHttpRequest();
}
function makerequest(serverpage,objID)
{
var obj=document.getElementById(objID);
xmlhttp.open("GET",serverpage);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
obj.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
</script>
<body onload="makerequest('content1.html','hw')">
<div align="center">
<h1>MY WEBpage</h1>
<span style="cursor:hand;" onclick="makerequest('content1.html','hw');">Page 1</span>
|<span style="cursor:hand;" onclick="makerequest('content2.html','hw');">Page 2</span>
|<span style="cursor:hand;" onclick="makerequest('content3.html','hw');">Page 3</span>
<div id="hw"></div>
</div>
</body>
</html>大家看这程序有没有问题?????????????
<head>
<title>例子</title>
</head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312"/>
<script language=javascript>
var xmlhttp;
if(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
xmlhttp=new XMLHttpRequest();
}
function makerequest(serverpage,objID)
{
var obj=document.getElementById(objID);
xmlhttp.open("GET",serverpage);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
obj.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
</script>
<body onload="makerequest('content1.html','hw')">
<div align="center">
<h1>MY WEBpage</h1>
<span style="cursor:hand;" onclick="makerequest('content1.html','hw');">Page 1</span>
|<span style="cursor:hand;" onclick="makerequest('content2.html','hw');">Page 2</span>
|<span style="cursor:hand;" onclick="makerequest('content3.html','hw');">Page 3</span>
<div id="hw"></div>
</div>
</body>
</html>大家看这程序有没有问题?????????????
<span style="cursor:hand;" onclick="makerequest('content1.html','hw');">Page 1</span>
|<span style="cursor:hand;" onclick="makerequest('content2.html','hw');">Page 2</span>
|<span style="cursor:hand;" onclick="makerequest('content3.html','hw');">Page 3</span>静态网页管用么?ajax本来就是异步刷新,你请求静态网页不管用的
if(xmlhttp.readyState==4&&xmlhttp.status==200)
条件不会成立
用file:///这样访问是不行的,根本是http请求。
$.ajax(
url:"content1.html",
dateType:"html",
success:function(data,Status){
alert(data);
}
)