As a result of the work, some client software interface with Html+css+javascript implementation, these files are placed in the client local, as a local file loading, but in some cases, need to connect to the server to obtain some information, if do not do any processing, the request failed, the information returned is as follows:
No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' null ' is therefore not allowed access.
This is because the browser's cross-domain policy works, blocking requests across domains. Look at the HTTP request process and know it. On the first request, the browser realized that it was accessing a cross and resource and did not send a GET request directly to fetch the data, but instead sent a options request asking if the resource could be accessed. We call it the preflight request, which failed because the request returned a header that did not have the ' access-control-allow-origin ' attribute because of the existence of the homologous policy.
If you want to implement Cross-domain, the key is the server, the client's code is written in the normal way. For a server, you only need to add this property to the header information returned in the place where you receive the options request, and the code is as follows:
Header ("Access-control-allow-origin: *");
Note that it must be set before all information is exported to the client.
The above is a small series to introduce you to the PHP how to achieve cross-domain related content, I hope to help you!