我有一个问题,我想使用 jQuery 从 XML 文件中获取一些数据(如果我可以说它是 XML 文件):
这是我的 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);
});
}
});
但这是数据:
<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>
因为它有“<string ...>
它不起作用...
有人可以建议如何修复它,或者也许还有其他方法可以修复...
多谢 !!!!!!
如果 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);
});
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)