javascript - Extract XML data from ajax result -


my ajax call this

$.ajax({     url: '/services/ltlgadgetv2.aspx',     type: 'get',     success: function (result) {               console.log( result);  }     }); 

in console result:

enter image description here sample xml

  <rateresults xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <pricesheets>   <pricesheet type="cost" currencycode="usd" createdate="0001-01-01t00:00:00">     <laneid>9553</laneid>     <maxdeficitweight>19999</maxdeficitweight>   </pricesheet> </pricesheets> <statuscode>0</statuscode> <statusmessage>rating process completed no errors</statusmessage> <debug>   <debug>     <contractname>2013  pinnacpccle </contractname>   </debug> </debug> <pricingmodel><![cdata[<div id="pricingmodeldiv" style="position:absolute;display:none;"><table id="mytable" width = "300" style="font-family:verdana; background:white; font-size:9" border="1"> </table></div>]]></pricingmodel> </rateresults> 

can please point out how xml data inside response can make operations on it? want parse output proper xml this

   var xmldocnp;     xmldocnp = $.parsexml('<xml>' + result + '</xml>'),      $xml = $(xmldocnp),     pricingmodel = $xml.find('pricingmodel').text(); 

but in order it, first need extract xml data above result

note: xml data starts rateresults tag

note: if put break-point , checked result in chrome, looks 

enter image description here

since result object, not string, there no need use $.parsexml():

var $xml = $(result); var pricingmodel = $xml.find('pricingmodel').text(); 

the reason if don't set datatype of result data in ajax request parameters, jquery uses intelligent guess understand data is. since jquery has correctly guessed xml, executed $.parsexml() internally , passed object instead of string success callback.

jquery.ajax() docs.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

oracle - Changing start date for system jobs related to automatic statistics collections in 11g -