CORS error on same domain?

2019-01-04 11:42发布

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

2条回答
看我几分像从前
2楼-- · 2019-01-04 12:15

The port numbers are different.

A request is considered cross-domain if any of the scheme, hostname, or port do not match.

查看更多
够拽才男人
3楼-- · 2019-01-04 12:25

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: *
查看更多
登录 后发表回答