This article by setting the access-control-allow-origin to achieve cross-domain. For example: The domain name of the client is client.runoob.com, and the requested domain name is server.runoob.com. If you use AJAX access directly, you will get the following error: XMLHttpRequest cannot load http://server.runoob.com/server.php. No ' Access-control-allow-origin ' header is present on the requested resource. Origin 'http://client.runoob.com' is therefore not allowed access.
1 , allowing single domain access to specify a domain name (http://client.runoob.com) Cross-domain access, you only need to be in http://Add the following code to the server.runoob.com/server.php file header:Header'access-control-allow-origin:http://client.runoob.com');
2 , allowing multiple domain names to be accessed by specifying multiple domain names (http://client1.runoob.com,http://client2.runoob.comand so on) cross-domain access, you only need the http://Add the following code to the server.runoob.com/server.php file header:$origin = Isset ($_server['Http_origin'])? $_server['Http_origin'] :"'; $allow _origin=Array ('http://client1.runoob.com', 'http://client2.runoob.com' ); if(In_array ($origin, $allow _origin)) {Header ('Access-control-allow-origin:'. $origin); }
3 , allowing all domain access to allow all domain name access is only required on http://Add the following code to the server.runoob.com/server.php file header:Header'access-control-allow-origin:*');
PHP Ajax the best solution for cross-domain problems