如何在jQuery中解析这个只在属性中存储值的XML?
我通过$.post()调用了这个XML,这是返回值:如何在jQuery中解析这个只在属性中存储值的XML?,jquery,xml,xml-parsing,Jquery,Xml,Xml Parsing,我通过$.post()调用了这个XML,这是返回值: <processResponse xmlns:client="http://xmlns...." xmlns="http://xmlns..." xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/so
<processResponse xmlns:client="http://xmlns...." xmlns="http://xmlns..." xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns2:ProcessResult xmlns:ns2="http://xmlns...">
<ns2:StatusCode>SUCCESS</ns2:StatusCode>
<ns2:StatusMessages>
<ns2:StatusMessage>
<ns2:Code>0</ns2:Code>
<ns2:Message>Success</ns2:Message>
</ns2:StatusMessage>
</ns2:StatusMessages>
</ns2:ProcessResult>
<premises>
<ns3:cwsPremise xmlns:ns3="http://xmlns..">
<ns3:cwsPremiseService>
<ns3:cwsPremiseHeader PremiseID="5855654654"/>
<ns3:cwsPremiseDetails PremiseID="5855654654" PremiseType="BBBB" Address="3892 A street" City="PA" Postal="96456" PremiseDataArea="PB" PremiseInfo="b55" District="a333" IsMultiple="N" AllowSelfService="Y" NeedAppointment="N"/>
</ns3:cwsPremiseService>
</ns3:cwsPremise>
<ns3:cwsPremise xmlns:ns3="http://xmlns...">
<ns3:cwsPremiseService>
<ns3:cwsPremiseHeader PremiseID="99565423587"/>
<ns3:cwsPremiseDetails PremiseID="99565423587" PremiseType="AAAA" Address="123 Main street" City="SC" Postal="98652" PremiseDataArea="AE" PremiseInfo="K876" District="b999" IsMultiple="N" AllowSelfService="Y" NeedAppointment="N"/>
</ns3:cwsPremiseService>
</ns3:cwsPremise>
</premises>
</processResponse>
JQuery::attr()返回字符串,而不是JQuery对象。在不使用.text()调用的情况下尝试
首先尝试解析xml,如果不将数据类型指定为xml,则不会返回XMLDocument,而只返回字符串
$.post(url, function(xml) {
var $PremiseID = $($.parseXML(xml)).find('cwsPremiseDetails').attr('PremiseID');
console.log($PremiseID);
});
检查控制台是否有错误,同时
attr()
返回字符串。捕捉良好,但返回未定义。
var $PremiseID = $(xml).find('cwsPremiseDetails').attr('PremiseID');
$.post(url, function(xml) {
var $PremiseID = $($.parseXML(xml)).find('cwsPremiseDetails').attr('PremiseID');
console.log($PremiseID);
});