002 Ajax中傳輸格式為HTML


一:

1.介紹

  返回的數據可以直接插入到需要的地方。

  

 

2.優缺點

  

 

二:程序大綱

1.結構

  

 

三:程序

1.css

body {
  background: #ffb url("logo.png") fixed no-repeat top left;
  color: #321;
  font-family: Myriad,"Lucida Grande","Trebuchet MS",Verdana,Helvetica,Arial,sans-serif;
  line-height: 1.6;
  margin: 1em 20%;
}
a {
  color: #aaf;
  font-weight: bold;
  text-decoration: none;
}
a:hover {
  color: #896;
  text-decoration: underline;
}

  

2.andy.html(files下的幾個程序結構相同,這里寫andy.html)

<h2><a href="mailto:andy@clearleft.com">Andy Budd</a></h2>
<a href="http://andybudd.com/">http://andybudd.com/</a>

  

3.index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	@import url("clearleft.css");
</style>
<script type="text/javascript">
	window.onload=function(){
		var aNodes=document.getElementsByTagName("a");
		for(var i=0;i<aNodes.length;i++){
			aNodes[i].onclick=function(){
				var request=new XMLHttpRequest();
				var method="GET";
				var url=this.href;
				request.open(method,url);
				request.send(null);
				request.onreadystatechange=function(){
					if(request.readyState==4){
						if(request.status==200||request.status==304){
							document.getElementById("details").innerHTML=request.responseText;
						}
					}
				}
				return false;
			}	
		}	
	}
</script>
</head>
<body>
	<h1>People</h1>
	<ul>
		<li><a href="files/andy.html">Andy</a></li>
		<li><a href="files/richard.html">Richard</a></li>
		<li><a href="files/jeremy.html">Jeremy</a></li>	
	</ul>
	<div id="details"></div>
</body>
</html>

  

4.運行效果

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM