Problem of Cors, in Ajax with PHP

0

Does anyone know why this error originates? I'm calling a file via ajax, and that's what's on the console. The caller and the receiver are in the same domain. what you are calling is a list for a select, if I open it from the direct URL if the list is answered.

Failed to load : Response to preflight request does not pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.

    
asked by normalito1212 14.09.2017 в 01:06
source

2 answers

2

Add the following to the beginning of your service in PHP, this can be useful in tests:

 header("Access-Control-Allow-Origin: *");

With this you will be allowing requests from any domain.

Greetings.

    
answered by 14.09.2017 в 02:33
0

I have seen this warning in other cases, the server where you are getting the service has the policy of access control from origin, which does not let you consume the service if it is not from the site itself. Therefore if you are trying to consume the service from your pc for example, will not allow giving the happy notice.

Here is a link where they explain this and some possible solutions.

link

I hope you serve, greetings.

    
answered by 14.09.2017 в 02:38