CORS错误在同一个域? [英] CORS error on same domain?
问题描述
我遇到一个奇怪的CORS问题现在。
I'm running into a weird CORS issue right now.
下面的错误消息:
XMLHttpRequest cannot load http://localhost:8666/routeREST/select?q=[...]
Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin
两台服务器:
Two servers:
- 在本地主机:8666 / routeREST /:这是一个简单的Python瓶服务器
- 在本地主机:8080 /:Python的simpleHTTPserver,我跑Ÿ的Javascript应用程序。这个程序是执行Ajax请求的服务器上面。
这可能是什么问题任何想法?
Any thought on what could be the problem?
编辑:
和...端口是问题。谢谢您的回答:)
And... the port was the problem. Thanks for your answers :)
如果任何人有使用Python的瓶子服务器,以及,你可以按照这个帖子来解决CORS问题给出了答案: <一href="http://stackoverflow.com/questions/17262170/bottle-py-enabling-cors-for-jquery-ajax-requests">Bottle潘岳:启用CORS的jQuery AJAX请求
If anyone is using a Python bottle server as well, you can follow the answer given on this post to solve the CORS issue: Bottle Py: Enabling CORS for jQuery AJAX requests
推荐答案
它仅被认为是相同的,如果的协议的主机的和的端口的是一样的:同源策略
It is only considered to be the same if the protocol, host and port is the same: Same Origin Policy
。 Mozilla有例子
If you want to enable it you must follow cors by adding headers. Mozilla has examples
您需要添加访问控制 - 允许 - 原产地在您的响应头。为了让大家(你应该的的不是的这样做):
You need to add Access-Control-Allow-Origin as a header in your response. To allow everyone (you should probably NOT do that):
Access-Control-Allow-Origin: *
这篇关于CORS错误在同一个域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!