JQuery读取XML文档

test.xml

<ajax> <title>Ajax-XML</title> <content>Hello A ,How old are you???</content> <usr id="1"> <name>Dante</name> <age>23</age> </usr> </ajax>

 

ajax.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <mce:script type="text/javascript" src="lib/jquery-1.3.2.min.js" mce_src="lib/jquery-1.3.2.min.js"></mce:script> <mce:script type="text/javascript"> $(document).ready(function(){ //Ajax读取XML $.get("test.xml",function(data){ var title = $("title",data).text(); var name = $("usr name",data).text(); var id = $("usr",data).attr('id'); $("div#dv1").html(title+"<br>"+name+"<br>"+id); }); }); <title>4-2.html</title> </head> <body> <fieldset> <legend>Get XML</legend> <div id="dv1"></div> </fieldset> </body> </html>

你可能感兴趣的:(JQuery读取XML文档)