PHP Cross-domain Setting

In the previous article 《jQuery $.ajax Method Ignored the Undefined Values》, I send a request to the server's php file, maybe you would get a cross-domain error.

XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Because in the default setting, the brower is believe your request is Illegal and unsafe, so your request would be rejected.


You can change the default setting in you php files, there is three basic setting.

header('Access-Control-Allow-Methods:POST');  //set the allow method

In common condition, you just need the first one.

 标签: PHP, Cross-domain

作者  :  sailor