Javascript 使用YQL通过jQuery解析XML(IE问题)
我编写了一个脚本,用jQuery解析XML文件,因为它在另一个域上,所以我使用YQL作为代理 该脚本在Chrome、Safari和FF中运行良好。在使用IE开发者工具时,我可以看到XML文件,但在第一次ajax调用之后,它似乎没有运行任何东西。关于Opera,如果有人有一个类似于IE的XDomainRequest的修复程序,这将是值得赞赏的,但没有解决IE的问题那么重要。如果可能的话,我想通过不使用jsonp数据来解决这个问题Javascript 使用YQL通过jQuery解析XML(IE问题),javascript,jquery,yql,Javascript,Jquery,Yql,我编写了一个脚本,用jQuery解析XML文件,因为它在另一个域上,所以我使用YQL作为代理 该脚本在Chrome、Safari和FF中运行良好。在使用IE开发者工具时,我可以看到XML文件,但在第一次ajax调用之后,它似乎没有运行任何东西。关于Opera,如果有人有一个类似于IE的XDomainRequest的修复程序,这将是值得赞赏的,但没有解决IE的问题那么重要。如果可能的话,我想通过不使用jsonp数据来解决这个问题 $(document).ready(function() { //
$(document).ready(function() {
// detect IE CORS transport
if ('XDomainRequest' in window && window.XDomainRequest !== null) {
// override default jQuery transport
$.ajaxSettings.xhr = function() {
try { return new XDomainRequest(); }
catch(e) { }
};
// also, override the support check
jQuery.support.cors = true;
//runs in IE
alert('hi1');
}
// ajax call to get the xml-data from the YQL console
$.ajax(
//runs in IE
alert('hi2'),
{
url: 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20%0A%20%20%20from%20xml%20%0A%20%20where%20url%3D%22https%3A%2F%2Fwww.lightbet.com%2Fxmlfeeds.aspx%3Ftype%3DCasinoJackpots%22&diagnostics=true',
type: 'GET',
dataType: 'xml',
success : function(xml) {
//doesn't run in IE
alert('hi3');
// Run the function for each Game tag in the XML file
$('Game',xml).each(function game(i) {
var $this = $(this),
game = $this.attr("name")
// appned all the game names to a div
$("#game_name").append(game);
//doesn't run in IE
alert('hi4');
});
}});
})) 我应该先去jQuery bugs报告站点,因为那里有一张罚单 jaubourg的这个很棒的插件使它非常流畅:
另外,如果有人获得了Opera的插件或某种修复程序,那将非常受欢迎。JS fiddle link:由于yahooapi经常超时并且没有数据显示,我使用服务器端脚本获取本地副本,然后像以前一样使用jquery ajax调用。