Problem when performing XHR in the same domain (localhost)

5

Explanation:

I have an application running on a client computer, it worked normally for some time, then something happened that the system could only be accessed from outside and locally it did not work anymore .

Problem:

XHR is not getting accomplished and in firefox firebug returns me the following error:

  

"Request between sources blocked: Same source policy prohibits reading of remote resources in http://localhost:3581/datasnap/rest/TdssMloteamento/getLoteamento/true/ . This can be fixed by moving the resource to the same domain or by enabling CORS."

What is VERY strange, because to my understanding this error could occur if accessed from a different domain "outside" and not on the contrary, that would be the case of the local host working perfectly, and on localhost does not work anymore

How to solve this? What's really going on? because the logic of giving different source error does not apply since the system is running on the client and the client of the same computer itself does not get it.

    
asked by anonymous 10.09.2014 / 19:18

2 answers

1

Not only the domain , but the protocol (ex: http vs https ) and the port be the same. To resolve this problem, you must add the Access-Control-Allow-Origin parameter in the request header. In PHP, I believe it can be done with something like:

<?php    
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    
11.09.2014 / 08:45
0

I had the same problem. I was able to resolve including in the php file:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
    
07.02.2015 / 18:54