这个JavaScript的“Origin non null”:为什么?

时间:2011-11-01 15:01:02

标签: jquery ajax

  

可能重复:
  Cross-Domain Requests with jQuery

$(function () {
    (function getFeed() {
        $
            .get('http://feeds.bbci.co.uk/news/world/rss.xml')
            .done(function (feed) {
                console.info('\Feed received: ', feed);
                displayProgrammes(feed);
            })
            .fail(function () {
                console.info('\nError getting the feed.');
            })
    }());
});

这是一个简单的Ajax请求,仅此而已。然而我收到错误消息:

  

Access-Control-Allow-Origin不允许使用原点。

1 个答案:

答案 0 :(得分:2)

AJAX中的请求只能在同一个域中进行,这称为同源策略 - >

http://en.wikipedia.org/wiki/Same_origin_policy

(使用PHP作为代理解决此问题的方法示例:http://devtreats.blogspot.com/search/label/ajax

还有另一种方式...... YQL - > Cross-Domain Requests with jQuery