如何使用jquery解析原子提要

时间:2011-09-26 12:15:25

标签: jquery

我想知道如何使用jquery解析原子提取。

我有下面的提要网址

http://www.google.co.in/trends/hottrends/atom/hourly

以下是jsfiddle,但它不起作用

http://jsfiddle.net/sukumar/sWPkT/

2 个答案:

答案 0 :(得分:3)

要发出跨浏览器请求,请参阅我在评论中指出的链接。

您可以使用此代码:

<script src="jquery.js"></script>
<script src="jquery.jgfeed.js"></script>
<script>
$.jGFeed('http://twitter.com/statuses/user_timeline/26767000.rss',
  function(feeds){
    // Check for errors
    if(!feeds){
      // there was an error
      return false;
    }
    // do whatever you want with feeds here
    for(var i=0; i<feeds.entries.length; i++){
      var entry = feeds.entries[i];
      // Entry title
      entry.title;
    }
  }, 10);
</script>

不要忘记添加Google Feeds API插件(jquery.jgfeed.js)

Source

答案 1 :(得分:1)

如果您查看浏览器的JavaScript控制台,您可能会看到以下几行:

XMLHttpRequest cannot load http://www.google.co.in/trends/hottrends/atom/hourly. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin.

基本上,出于安全原因,您无法从一个域向另一个域发出AJAX请求。所有浏览器都强制执行此操作。