<span style="font-size:18px;">{"person": { "name":"Andy Budd", "website":"http://andybudd.com/", "email":"andy@clearleft.com" } }</span>
<%@ page language="java" pageEncoding="UTF-8"%> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>People at Clearleft</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 url=this.href; var method="GET"; request.open(method,url); request.send(null); request.onreadystatechange=function(){ if(request.readyState==4){ if(request.status==200||request==304){ var result=request.responseText; //json被存储在responseText属性中 var object=eval("("+result+")"); //读取responseText中的json数据 var name= object.person.name; //读取json对象中存储的数据 var website= object.person.website; var email= object.person.email; var aNode=document.createElement("a"); aNode.appendChild(document.createTextNode(name+":"+"email"+":"+website)); aNode.href="mailTo"+"email"+",website"; var h2Node=document.createElement("h2"); h2Node.appendChild(aNode); var dtails=document.getElementById("details"); details.innerHTML=""; //防止重复的添加字符串 dtails.appendChild(h2Node); } } } return false; } } }; </script> </head> <body> <h1> People </h1> <ul> <li> <a href="files/andy.js">Andy</a> </li> <li> <a href="files/richard.js">Richard</a> </li> <li> <a href="files/jeremy.js">Jeremy</a> </li> </ul> <div id="details"></div> </body> </html>
原文地址:http://blog.csdn.net/shiyeqiangldh/article/details/36026447