当前位置:编程学习 > XML/UML >>

jquery解析xml

 

$.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

});

补充:Web开发 , Jsp ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,