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.
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();
}
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.
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>
if I do console.log($xml)
and expand the object, this is what I see:
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.
Thanks!