Parsing xml in jQuery

前端 未结 2 394
南旧
南旧 2021-01-17 03:48

I have this xml file:

    Response: 

        
2条回答
  •  囚心锁ツ
    2021-01-17 04:22

    Here is one way to do it:

    var xml = null;
    function loadXML(myURL){
        $.ajax({
            type: "GET",
            url: myURL,
            dataType: ($.browser.msie) ? "text" : "xml",
            error: function(){
                return;
            },
            success: function(data){
                 if (typeof data == "string") {
                   xml = new ActiveXObject("Microsoft.XMLDOM");
                   xml.async = false;
                   xml.loadXML(data);
                    } else {
                   xml = data;
                 }
            }
        });
    };
    $(loadXML("common/glossary.xml"));
    

    then

    $(xml).find('something')
    

提交回复
热议问题