欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jquery解析xml

程序员文章站 2022-05-21 14:49:23
  $.ajax({           &nb...

 

$.ajax({

                     url:url,

                     type:"POST",

                     //data:params,

                     dataType: "xml",

                     async: false,

                     success:function(data){

                           

                            //alert(userid);

                            $(data).find("Root").each(function(i){

                                   var length=$(this).children("PhoneBookCard").length;       //所有对象的长度象

 

                                   for(var i=0;i<length;i++){

                                         

                                          var cardId=$($(this).children("PhoneBookCard").get(i)).find("cardId").text();        //每一个对象下面的节点对

                                          alert(cardId)

                                   }

                                  

                                  

                            });

//上面兼容所有浏览器

 

 

 

if(null!=data){

                                  

                                   var root=data.selectNodes("Root");

                                  

                                   for(var i=0;i<root.length;i++){

                                         

                                  

                                          var childNodes=root[i].childNodes;

                                          var childNodesLen=childNodes.length;

                                         

                                          for(var j=0;j<childNodesLen;j++){

                                          var cardId=$(childNodes[j]).find("cardId").text();      //id

                            //得到value值

              }

       }

}

//这个只兼容IE

});