六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 28|回复: 0

jquery ajax读取xml

[复制链接]

升级  77.33%

46

主题

46

主题

46

主题

秀才

Rank: 2

积分
166
 楼主| 发表于 2013-1-23 02:13:39 | 显示全部楼层 |阅读模式
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> 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表