没有“访问控制 - 允许 - 原产地”标头的请求的资源错误present [英] No 'Access-Control-Allow-Origin' header is present on the requested resource error

查看:136
本文介绍了没有“访问控制 - 允许 - 原产地”标头的请求的资源错误present的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想取一个新闻网站的饲料。以为我会使用谷歌的API饲料的FeedBurner资讯转换为JSON。以下URL将返回10个职位从进料,以JSON格式。 <一href="http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http://feeds.feedburner.com/mathrubhumi">http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http://feeds.feedburner.com/mathrubhumi

I'm trying to fetch the feed of a news website. Thought I'd use google's feed API to convert the feedburner feed into json. The following url will return 10 posts from the feed, in json format. http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http://feeds.feedburner.com/mathrubhumi

我用下面的code得到上面URL的内容

I used the following code to get the contents of above url

$.ajax({
            type:"GET",
            dataType:"jsonp",
            url:"http://ajax.googleapis.com/ajax/services/feed/load",
            data:{"v":"1.0", "num":"10", "q":"http://feeds.feedburner.com/mathrubhumi"},

            success: function(result){
                //.....
            }
        });

,但它不工作,我发现了以下错误

but it's not working and I'm getting the following error

XMLHtt prequest无法加载   <一href="http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Ffeeds.feedburner.com%2Fmathrubhumi">http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Ffeeds.feedburner.com%2Fmathrubhumi.   没有访问控制 - 允许 - 原产地标头的请求的present   资源。原产地的http://本地主机'。因此不会允许访问

XMLHttpRequest cannot load http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Ffeeds.feedburner.com%2Fmathrubhumi. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

我该如何解决这个问题?

How do I fix this?

推荐答案

我相信这可能会是,Chrome不支持本地主机要经过访问控制 - 允许 - 原产地 - 看到浏览器的问题[1]

I believe this might likely be that Chrome does not support localhost to go through the Access-Control-Allow-Origin -- see Chrome issue[1]

[1] <一个href="https://$c$c.google.com/p/chromium/issues/detail?id=67743">https://$c$c.google.com/p/chromium/issues/detail?id=67743

让Chrome发送访问控制 - 允许 - 原产地的头,只是别在你的​​/ etc本地主机/ hosts文件到其他领域,如:

To have Chrome send Access-Control-Allow-Origin in the header, just alias your localhost in your /etc/hosts file to some other domain, like:

127.0.0.1   localhost yourdomain.com

然后,如果你想使用访问你的脚本 yourdomain.com ,而不是本地主机中,调用应该会成功。

Then if you'd access your script using yourdomain.com instead of localhost, the call should succeed.

这篇关于没有“访问控制 - 允许 - 原产地”标头的请求的资源错误present的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆