Xml call using jQuery (invalid XML)

I have one problem, I want to get some data from an XML file (if you can say that it is an XML file), with jQuery:

This is my jQuery, it works with a regular XML file:

$.ajax({
        type: "GET",
        url: "test.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('result').each(function(){
            var bid = $(this).find('bid').text();
            alert(bid);
            });
            }
        });

But this is the data:

   <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
<?xml version="1.0" ?> 


<T_transmission> 
<result> 
<last>9.9200</last> 
<bid>9.9000</bid> 
<ask>9.9200</ask> 
<mid>9.9100</mid> 
</result> 

 </T_transmission>

</string>

Since it has, " <string ...>it does not work ...

Can someone suggest how to fix this, or maybe there is another way to fix it ...

Thank you so much!!!!!!

+5
source share
2 answers

If the xml format is completely out of your control, you can hack it a bit. This worked for me at FireFox.

$.ajax({
  type: "GET",
  url: "test.xml",

  // change dataType to 'text' so that jquery doesn't try to parse xml
  dataType: "text",
  success: function(xml) {

    // just remove the declaration using replace()
    xml = xml.replace('<?xml version="1.0" ?>', '');

    $(xml).find('result').each(function(){
    var bid = $(this).find('bid').text();
    alert(bid);
    });
  }
});
+11
source

, jquery , , jquery .

0

All Articles