用jQuery调用Xml,(无效的XML)

Ale*_*exC 5 xml string jquery get

我有一个问题,我想从XML文件中获取一些数据(如果我可以说它是XML文件),使用jQuery:

这是我的jQuery,它适用于普通的XML文件:

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

但这是数据:

   <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>
Run Code Online (Sandbox Code Playgroud)

因为它有" <string ...> 它不起作用......

有人可以建议如何解决它或者可能有另一种方法来修复...

非常感谢 !!!!!!

jes*_*vin 11

如果xml格式完全在你的控制范围之外,你可能会有点像这样.这对我在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);
    });
  }
});
Run Code Online (Sandbox Code Playgroud)

  • 我的妻子很乐意听到这个消息!别客气. (12认同)