Access-Control-Allow-Origin problems on the same domain

為{幸葍}努か 提交于 2019-12-11 01:32:46

问题


How is it possible that when I try to make an XMLHTTPRequest from a javascript file to a web service located on the very same domain, I get:

Origin http://mydomain.com is not allowed by Access-Control-Allow-Origin ???

If I change mydomain.com to localhost, I no longer have problems, but I would like to keep it as mydomain.com

What do I have to edit, and why in the first place, since it's the same domain?


回答1:


1) look in your request/response headers. Is the server returning a weird access-control-allow-origin header?

2) It's not just the domain, it's also the protocol (http vs https vs ftp etc), the port (if you have a :8080 or something like that), and potentially the part after the .com/




回答2:


It probably is because of the missing www. If you test with yourdomain.com and your site is at www.yourdomain.com it is concidered cross-domain and cross-domain calls are not allowed by default.



来源:https://stackoverflow.com/questions/8576252/access-control-allow-origin-problems-on-the-same-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!