AJAX數(shù)據(jù)格式之JSON
1、在Eclipse中創(chuàng)建項目目錄視圖如下:
2、代碼及注解如下
? ? ? ? ?
? ? ? ??andy.xml文件代碼如下所示:
{"person":{ "name":"Hello?Andy", "website":"http://www.test001.com/", "email":"andy@qq.com" } }
? ? ? ??index.html文件代碼及注解如下所示:
AJAX--數(shù)據(jù)格式--JSON節(jié)點 var?aNode?=?document.createElement('a'); aNode.appendChild(document.createTextNode(Tname)); aNode.href?=?"mailto:"?+?Temail; //?創(chuàng)建標(biāo)簽 var?h2Node?=?document.createElement('h2'); h2Node.appendChild(aNode); //?創(chuàng)建第2個標(biāo)簽 var?aNode2?=?document.createElement('a'); aNode2.appendChild(document.createTextNode(Twebsite)); aNode2.href?=?Twebsite; //?4、將拼寫得到的JSON數(shù)據(jù)信息添加到"id?=?'detail'"中 var?detailNode?=?document.getElementById('detail'); //?清空detailNode中的數(shù)據(jù) detailNode.innerHTML?=?""; detailNode.appendChild(h2Node); detailNode.appendChild(aNode2); } } } return?false; }??//?aNodes[i].onClick?=?function() }??//?for?(var?i?=?0;?i?PersonFirst?andySecond?jeremyThird?richard
3、運(yùn)行結(jié)果如下所示:
--------------------------------------------------------------------------------------------------------------------------------------------