在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1: JSON(JavaScriptObject Notation)一种简单的数据格式,比xml更轻巧。JSON是JavaScript原生格式,这意味着在JavaScript中处理JSON数据不需要任何特殊的API或工具包。 <span style="font-size:18px;">{"person": { "name":"Andy Budd", "website":"http://andybudd.com/", "email":"[email protected]" } }</span> JSON 只是一种文本字符串。它被存储在responseText 属性中 2:案例 <%@ 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> |
请发表评论