`

jQuery使用XML的例子

    博客分类:
  • Ajax
阅读更多

xml文档:
<?xml version="1.0"?>
<msglist>
<msg><ip>127.0.0.1</ip><time>2008-08-18 04:37:42</time><content><![CDATA[dfasfdsa]]></content></msg><msg><ip>127.0.0.1</ip><time>2008-08-18 04:37:51</time><content><![CDATA[fdsafdafdsa]]></content></msg><msg><ip>127.0.0.1</ip><time>2008-08-18 04:38:01</time><content><![CDATA[fdasfsdafdsa]]></content></msg><msg><ip>127.0.0.1</ip><time>2008-08-18 04:38:09</time><content><![CDATA[fdafdsafdsa]]></content></msg><msg><ip>127.0.0.1</ip><time>2008-08-18 04:38:17</time><content><![CDATA[fdasfdsafdsa]]></content></msg>
</msglist>

jQuery代码:

<SCRIPT. LANGUAGE="JavaScript">
<!--
   $("document").ready(function(){
     $.ajax({
             url: "guestbook.xml",
             dataType:   "xml", //这里注意的是应该加上这个
             success: function(xml){
   
              $(xml).find("msglist > msg").each(function(){
         alert($(this).find("content").text());
      });
      
      }
    })
     
   })
//-->
</SCRIPT>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics