`
zhiming_817
  • 浏览: 163819 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

jquery ajax读取xml

    博客分类:
  • ajax
阅读更多

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 楼 古月情殇 2011-09-16  
我有个问题想请问下,就是我的子节点有子节点。。例如"
<msglist>   
  <msg name="11">   
    <id>1</id>   
    <content>content1</content>   
  </msg>   
  <msg name="22">   
    <id>2</id>   
    <content>
         <con1></con1>
         <con2></con2>
    </content>   
  </msg>   
</msglist>

我怎么样拿到 con1 和 con2 值。求解答谢谢了。

相关推荐

Global site tag (gtag.js) - Google Analytics