2011-12-29 90 views
2

试图从Yahoo!获取RSS财政部根据安德鲁和Dylan瓦拉德答案在Parse RSS with jQuery但收到的错误:获取Yahoo!使用JQuery和Google API的财务RSS错误

data.responseData是空

成功() 数据= {对象= responseDetails“饲料无法加载。”,responseStatus = 400,responseData = NULL}

载入来自浏览器的相同的URL或PHP卷曲返回OK RSS数据

网址:http://feeds.finance.yahoo.com/rss/2.0/headline?s= ^富时, URL编码:HTTP%3A%2F%2Ffeeds.finance.yahoo .COM%2Frss%2F2.0%2Fheadline%3FS%3D% 5EFTSE

从我的Mac上的本地虚拟主机(OS X 10.5.8,XAMPP 1.7.3)进行测试。我尝试了使用Google API的zRSSfeed插件,并收到了同样的错误:“Feed无法加载”。索引数据和图表预先


function getRSS(symbol, url, callback) { 
    $('#rss').html('http://feeds.finance.yahoo.com/rss/2.0/headline?s='+symbol+'<br />'); 
    $('#rss').append(encodeURIComponent(url)); 
    $.ajax({ 
    url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url), 
    dataType: 'json', 
     success: 
      function (data) { 
       callback(data.responseData.feed); 
      }, 
     error: 
      function (jqXHR, textStatus, errorThrown) { 
       $('#rss').append('<span class="downVal">'+textStatus+'</span>'); 
       $('#rss').append('<br />'+'<span class="downVal">'+errorThrown+'</span>'); 
      } 
    }); 
} 

function parseRSS(newsFeed) { 
    $('#rss').append(newsFeed); 
} 

jQuery(document).ready(function($) { 
... 
    summary(symbol); 
    $('#chart').html('<img style="-webkit-user-select:none" src="http://chart.finance.yahoo.com/z?s='+symbol+'&t=3m&q=l&l=on&z=m&p=m20,m200,v&a=r14,m26-12-9">'); 
    getRSS(symbol, 'http://feeds.finance.yahoo.com/rss/2.0/headline?s='+symbol, parseRSS); 
... 

回答

3

首先要指出工作正常

由于是,进料返回一个400码 - 从而根据W3C recommendations, you shouldn't repeat the call

10.4.1 400 Bad Request

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

当我打开网址:

http://feeds.finance.yahoo.com/rss/2.0/headline?s=^FTSE 

我得到一个404错误,所以也许搜索不总是有效的或者是速率限制?

如果你确信该呼叫是OK,那么有可能是与调用进行了一个问题:

$('#rss').html('http://feeds.finance.yahoo.com/rss/2.0/headline?s='+symbol+'<br />' 

所以剥离回来,提醒了符号变量,以确保它是你想要的,加上线像一些基本的调试以下内容:

alert (symbol); 
var feedUrl = 'http://feeds.finance.yahoo.com/rss/2.0/headline?s='+symbol; 
alert (feedUrl); 

...最后检查是否追加<br />实际上是打破了饲料网址。

+0

感谢您的建议,它帮助我找到了问题。区域和语言url参数是必需的,但我认为它们是可选的,因为我对文档感到困惑:“那么您可以使用语言/区域本地化提要结果”。此外,你必须编码“^”字符,指出它是一个指数,而不是股票;我在我的代码中完成了,但在帖子中省略了该行。所以,正确的网址是:http://feeds.finance.yahoo.com/rss/2.0/headline?s=%5EFTSE®ion=US&lang=en-US – hsands 2011-12-30 01:47:15