无法使用jQuery提取SOAP XML [英] Cannot extract SOAP XML with jQuery

查看:65
本文介绍了无法使用jQuery提取SOAP XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery在成功回调中使用以下代码从AJAX响应中提取SOAP XML数据.我正在使用 https://api.jquery.com/jQuery.parseXML/供参考.我不使用$.parseXML()函数的原因是因为data已经是已解析的响应,并且尝试再次解析它会呈现空响应.

I'm using jQuery to extract SOAP XML data from an AJAX response using the following code inside the success callback. I'm using the example from https://api.jquery.com/jQuery.parseXML/ for reference. The reason I'm not using the $.parseXML() function is because data is already a parsed response and attempting to parse it again renders a null response.

我的成功回调(curShipment是用于以JSON格式存储所需信息的变量,您可以忽略它):

My success callback (curShipment is a variable for storing the required info in a JSON format, you can ignore it):

success: function(data) {
  var $xml = $( data );
  if ($xml.find("error").text() != "") {
    resetUI();
    alertMessage($xml.find("error").text(), "danger");
  } else {
    curShipment.labelId = $xml.find("id").first().text();
    curShipment.loo_wb = $xml.find('value').first().text();
    curShipment.senderName = $xml.find('pickup_name').text();
    curShipment.consigneeName = $xml.find('delivery_name').text();
    saveShipment();
  }

该代码最初在上周在Chrome中运行,一旦Chrome更新到v60,它将不再起作用.我将这归咎于Chrome错误,但事实是它从未在Firefox或Internet Explorer中起作用.因此,很明显,我的代码存在一个问题,即Chrome在以前的版本中已以某种方式解决.任何建议将不胜感激-我对jQuery的了解很少.

This code was originally working in Chrome last week and once Chrome updated to v60 it no longer does. I would blame this on a Chrome bug except for the fact it never worked in Firefox or Internet Explorer. So, obviously, there's an issue with my code that Chrome was somehow working around in the previous version. Any advice would be greatly appreciated - I have very little jQuery experience.

这是console.log(data)(很长很抱歉-我实际上删除了其中一半):

Here's console.log(data) (sorry it's so long - I actually removed half of it):

    <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns:processShipmentResponse xmlns:ns="http://ws.business.uss.transforce.ca">
         <ns:return xsi:type="ax25:ProcessShipmentRs" xmlns:ax27="http://dto.uss.transforce.ca/xsd" xmlns:ax25="http://ws.business.uss.transforce.ca/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ax25:error xsi:nil="true"/>
            <ax25:processShipmentResult xsi:type="ax27:ProcessShipmentResult">
               <ax27:shipment xsi:type="ax27:Shipment">
                  <ax27:billed_weight>21.0</ax27:billed_weight>
                  <ax27:billed_weight_unit>L</ax27:billed_weight_unit>
                  <ax27:collect_shipper_num/>
                  <ax27:consolidation_type/>
                  <ax27:courier>L</ax27:courier>
                  <ax27:delivery_address_id/>
                  <ax27:delivery_address_line_1>123 MAIN ST</ax27:delivery_address_line_1>
                  <ax27:delivery_address_line_2>STE 200</ax27:delivery_address_line_2>
                  <ax27:delivery_address_line_3/>
                  <ax27:delivery_city>MISSISSAUGA</ax27:delivery_city>
                  <ax27:delivery_country>CA</ax27:delivery_country>
                  <ax27:delivery_email>DELIVERIES@LOOMIS-EXPRESS.COM</ax27:delivery_email>
                  <ax27:delivery_extension>1234</ax27:delivery_extension>
                  <ax27:delivery_name>COMPANY NAME HERE</ax27:delivery_name>
                  <ax27:delivery_phone>9055551212</ax27:delivery_phone>
                  <ax27:delivery_postal_code>L5R3R3</ax27:delivery_postal_code>
                  <ax27:delivery_province>ON</ax27:delivery_province>
                  <ax27:delivery_residential>false</ax27:delivery_residential>
                  <ax27:dimension_unit>I</ax27:dimension_unit>
                  <ax27:estimated_delivery_date xsi:nil="true"/>
                  <ax27:freight_charge>0.00</ax27:freight_charge>
                  <ax27:fuel_surcharge>1.20</ax27:fuel_surcharge>
                  <ax27:id>10000734</ax27:id>
                  <ax27:inserted_on>2017-04-07T11:03:30.508-04:00</ax27:inserted_on>
                  <ax27:manifest_num xsi:nil="true"/>
                  <ax27:packages xsi:type="ax27:Package">
                     <ax27:billed_weight>20.5</ax27:billed_weight>
                     <ax27:dim_weight>0.0</ax27:dim_weight>
                     <ax27:dim_weight_flag>false</ax27:dim_weight_flag>
                     <ax27:id>10005262</ax27:id>
                     <ax27:inserted_on>2017-04-07T11:03:30.508-04:00</ax27:inserted_on>
                     <ax27:min_weight_flag>false</ax27:min_weight_flag>
                     <ax27:package_info_str xsi:type="ax27:PackageInfoStr">
                        <ax27:id>10002317</ax27:id>
                        <ax27:inserted_on>2017-04-07T11:03:31.241-04:00</ax27:inserted_on>
                        <ax27:name>PIN</ax27:name>
                        <ax27:updated_on>2017-04-07T11:03:31.241-04:00</ax27:updated_on>
                        <ax27:value>LSHA00007014</ax27:value>
                     </ax27:package_info_str>
                     <ax27:package_num>0</ax27:package_num>
                     <ax27:package_reference>0</ax27:package_reference>
                     <ax27:reported_weight>20.5</ax27:reported_weight>
                     <ax27:updated_on>2017-04-07T11:03:31.241-04:00</ax27:updated_on>
                  </ax27:packages>
                  <ax27:pickup_address_line_1>5555 DIXIE RD</ax27:pickup_address_line_1>
                  <ax27:pickup_address_line_2>BUILDING 2</ax27:pickup_address_line_2>
                  <ax27:pickup_address_line_3>STE 500</ax27:pickup_address_line_3>
                  <ax27:pickup_city>MISSISSAUGA</ax27:pickup_city>
                  <ax27:pickup_email>SHIPPING@LOOMIS-EXPRESS.COM</ax27:pickup_email>
                  <ax27:pickup_extension>6162</ax27:pickup_extension>
                  <ax27:pickup_name>LOOMIS EXPRESS</ax27:pickup_name>
                  <ax27:pickup_phone>9054528769</ax27:pickup_phone>
                  <ax27:pickup_postal_code>L4W1E6</ax27:pickup_postal_code>
                  <ax27:pickup_province>ON</ax27:pickup_province>
                  <ax27:proforma xsi:nil="true"/>
                  <ax27:reported_weight_unit>L</ax27:reported_weight_unit>
                  <ax27:service_type>DD</ax27:service_type>
                  <ax27:shipment_info_str xsi:type="ax27:ShipmentInfoStr">
                     <ax27:id>10005201</ax27:id>
                     <ax27:inserted_on>2017-04-07T11:03:31.194-04:00</ax27:inserted_on>
                     <ax27:name>CODE</ax27:name>
                     <ax27:updated_on>2017-04-07T11:03:31.241-04:00</ax27:updated_on>
                     <ax27:value>AA</ax27:value>
                  </ax27:shipment_info_str>
                  <ax27:shipment_info_str xsi:type="ax27:ShipmentInfoStr">
                     <ax27:id>10005202</ax27:id>
                     <ax27:inserted_on>2017-04-07T11:03:31.194-04:00</ax27:inserted_on>
                     <ax27:name>SERVICE_LABEL</ax27:name>
                     <ax27:updated_on>2017-04-07T11:03:31.241-04:00</ax27:updated_on>
                     <ax27:value>GRD</ax27:value>
                  </ax27:shipment_info_str>
                  <ax27:shipment_info_str xsi:type="ax27:ShipmentInfoStr">
                     <ax27:id>10005203</ax27:id>
                     <ax27:inserted_on>2017-04-07T11:03:31.194-04:00</ax27:inserted_on>
                     <ax27:name>BRANCH_CITY</ax27:name>
                     <ax27:updated_on>2017-04-07T11:03:31.241-04:00</ax27:updated_on>
                     <ax27:value>BRAMPTON</ax27:value>
                  </ax27:shipment_info_str>
                  <ax27:shipment_info_str xsi:type="ax27:ShipmentInfoStr">
                     <ax27:id>10005204</ax27:id>
                     <ax27:inserted_on>2017-04-07T11:03:31.241-04:00</ax27:inserted_on>
                     <ax27:name>SIN</ax27:name>
                     <ax27:updated_on>2017-04-07T11:03:31.241-04:00</ax27:updated_on>
                     <ax27:value>LSHA00007014</ax27:value>
                  </ax27:shipment_info_str>
                  <ax27:shipment_status>R</ax27:shipment_status>
                  <ax27:shipper_num>HB4499</ax27:shipper_num>
                  <ax27:shipping_date>20170407</ax27:shipping_date>
                  <ax27:tax_charge_1>1.26</ax27:tax_charge_1>
                  <ax27:tax_charge_2>0.00</ax27:tax_charge_2>
                  <ax27:tax_code_1>GST</ax27:tax_code_1>
                  <ax27:tax_code_2/>
                  <ax27:transit_time>1</ax27:transit_time>
                  <ax27:transit_time_guaranteed>false</ax27:transit_time_guaranteed>
                  <ax27:updated_on>2017-04-07T11:03:31.241-04:00</ax27:updated_on>
                  <ax27:user_id>ADMIN@USS.COM</ax27:user_id>
                  <ax27:voided>false</ax27:voided>
                  <ax27:zone>1</ax27:zone>
               </ax27:shipment>
            </ax25:processShipmentResult>
         </ns:return>
      </ns:processShipmentResponse>
   </soapenv:Body>
</soapenv:Envelope>

如果我执行console.log($xml)并展开对象,这就是我看到的:

if I do console.log($xml) and expand the object, this is what I see:

屏幕截图

我展开了documentElement,它是肥皂信封,在该对象下,您可以在innerHTML元素内看到其余的XML.

I expanded the documentElement which is the soap envelope and under that object, you can see the rest of the XML within the innerHTML element.

谢谢!

推荐答案

添加带有\\:的命名空间可解决此问题.以下回调适用于Chrome,Firefox和Amp; IE.但是,它在Edge上不起作用.仅当未指定名称空间时,Edge才起作用.

Adding the namespace with \\: appended fixed the issue. The following callback works on both Chrome, Firefox & IE. However, it does not work on Edge. Edge only works when no namespace is specified.

success: function(data) {
  var $xml = $( data );
  if ($xml.find("ax25\\:error").text() != "") {
    resetUI();
    alertMessage($xml.find("ax25\\:error").text(), "danger");
  } else {
    curShipment.labelId = $xml.find("ax27\\:id").first().text();
    curShipment.loo_wb = $xml.find('ax27\\:value').first().text();
    curShipment.senderName = $xml.find('ax27\\:pickup_name').text();
    curShipment.consigneeName = $xml.find('ax27\\:delivery_name').text();
    saveShipment();
  }

这篇关于无法使用jQuery提取SOAP XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆