同一域(localhost)上的XHR跨域错误 [英] XHR cross-domain error on the same domain (localhost)
问题描述
我在使用javascript进行某些XHR的计算机上的apache服务器上运行了一个小型Web应用程序.很长时间以来,它一直没有问题,但是今天,所有XHR都停止工作了,但只能在localhost上运行,如果您从外部访问它的话,它的运行效果很好.
I have a small web application running on apache server on a machine that uses javascript to do some XHR's. For a long time it worked with no problems, today all the XHR's stopped working but only on localhost, if you access it from outside it works perfectly.
firebug警告:使用mozilla firefox:
Using mozilla firefox, firebug warns:
"跨域请求被阻止:同一起源策略不允许在
http://127.0.0.1:3581/datasnap/rest/TdssMloteamento/getLoteamento/true/
处读取远程资源.可以通过将资源移至相同域或启用CORS来解决此问题."
"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
http://127.0.0.1:3581/datasnap/rest/TdssMloteamento/getLoteamento/true/
. This can be fixed by moving the resource to the same domain or enabling CORS."
但是我在本地主机上访问具有XHR的本地内容,该内容在同一台机器上调用了本地datasnap服务器,在本地恢复,并在网络上失败了.
But i'm on localhost acessing a local content that have XHR calls a local datasnap server on the same machine, resuming, locally it fails, and from web it works.
我正在访问URL中的apache网页:http://127.0.0.1:3582/beeWebLoteamento/Principal.php
I am acessing apache web page within url: http://127.0.0.1:3582/beeWebLoteamento/Principal.php
这对我来说完全是古怪,这毫无意义,没有逻辑,如果我使用相同的域,为什么会出现跨域错误?
This is totally, really, weird for me, that just does not make sense, no-logic, why i get a cross-domain error if i'm acessing the same domain?
我想知道发生了什么并解决此问题,以便继续在本地和通过Web(外部)进行XHR.
I want to know what is happening and solve this problem to continue doing my XHR's locally and via the web (external) too.
推荐答案
我找到了解决方案/问题,即:
将所有127.0.0.1
替换为192.168.25.100
(即本地计算机ip),并且一切正常,因此请求为:
I found the solution/problem, that is:
Replaced all 127.0.0.1
to 192.168.25.100
(that is the local machine ip) and everything worked fine, so the request was:
http://127.0.0.1:3581/datasnap/rest/TdssMloteamento/getLoteamento/true/
并成为:
http://192.168.25.100:3581/datasnap/rest/TdssMloteamento/getLoteamento/true/
然后我在URL中访问了我的Web应用程序(apache):
And i acessed my web application (apache) within the URL:
http://192.168.25.100:3582/beeWebLoteamento/Principal.php
恢复:
为避免这些跨域问题,请使用计算机通常以192.168.xxx.xxx
开头"的本地ip地址.可以访问托管在其上的所有内容,也可以访问XHR或Apache,而不是使用127.0.0.1
或localhost
Resuming:
To avoid these cross-domain problems, use the local ip address of the machine "that usually starts with 192.168.xxx.xxx
" to access everything that are hosted on it, nor XHR either Apache, instead of using 127.0.0.1
or localhost
这篇关于同一域(localhost)上的XHR跨域错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!