zhiming_817 发表于 2013-1-23 02:13:39

jquery ajax读取xml

xml.html
<html> <head><script type="text/javascript" src="jquery-1.4.1.js"></script><script type="text/javascript">   $(document).ready   (   function()      {       $("a").click       (      function()         {         hello();      }       );      }   );function hello(){$.ajax({               url:"xml.xml",               dataType:"xml",               error: function(xml){                     alert('Error loading XML document'+xml);               },               success:function(xml){               alert($(xml).find("content").text());                  $(xml).find("msglist > msg").each(function(){                         alert($(this).find("content").text());//each是循环执行,即多次弹出。                         alert($(this).attr("name"));//取得属性的方法                     });               }             })}    </script> </head><body><a onclick='alert("helloworld")' href="#" >helloworld</a>   </body> </html>xml.xml
 
<msglist>   <msg name="11">   <id>1</id>   <content>content1</content>   </msg>   <msg name="22">   <id>2</id>   <content>content2</content>   </msg> </msglist> 
 
页: [1]
查看完整版本: jquery ajax读取xml