CORS错误在同一个域? [英] CORS error on same domain?

查看:217
本文介绍了CORS错误在同一个域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在遇到一个奇怪的CORS问题。



以下是错误讯息:

  XMLHttpRequest无法加载http: / localhost:8666 / routeREST / select?q = [...] 
原产地http:// localhost:8080 Access-Control-Allow-Origin不允许



两个服务器:




  • localhost:8666 / routeREST /:这是一个简单的Python瓶子服务器。

  • localhost:8080 /:Python simpleHTTPserver我运行Javascript应用程序。这个应用程式正在上方的伺服器上执行Ajax要求。



有什么可能的问题吗?



编辑:



而且端口是问题。感谢您的答案:)



如果任何人也使用Python瓶子服务器,你可以按照这篇文章的答案解决CORS问题:
Bottle Py:为jQuery AJAX请求启用CORS


解决方案

如果协议主机 端口是相同的:同源政策



如果您要启用它,您必须遵循 cors 添加标题。 Mozilla有示例



您需要在响应中将Access-Control-Allow-Origin添加为标头。允许所有人(您应该 ):

  Access-Control-Allow-Origin:* 


I'm running into a weird CORS issue right now.

Here's the error message:

XMLHttpRequest cannot load http://localhost:8666/routeREST/select?q=[...] 
Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin

Two servers:

  • localhost:8666/routeREST/ : this is a simple Python Bottle server.
  • localhost:8080/ : Python simpleHTTPserver where I run y Javascript application. This app is executing Ajax requests on the server above.

Any thought on what could be the problem?

EDIT:

And... the port was the problem. Thanks for your answers :)

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

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屋!

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