What is cross domain.
Cross-domain, refers to the browser can not execute other Web site script. It is caused by the browser's homology policy and is the security restrictions imposed by the browser .
The so-called homology refers to, domain name, protocol, port are the same, do not understand it doesn't matter, give a chestnut:
http://www.123.com/index.html Call http://www.123.com/server.php (non-Cross-domain)
http://www.123.com/index.html Call http://www.456.com/server.php (main domain name is different: 123/456, Cross-domain)
http://abc.123.com/index.html Call http://def.123.com/server.php (sub domain name is different: Abc/def, Cross-domain)
http://www.123.com:8080/index.html Call http://www.123.com:8081/server.php (port is different: 8080/8081, Cross-domain)
http://www.123.com/index.html call https://www.123.com/server.php (protocol different: Http/https, Cross-domain)
Note that localhost and 127.0.0.1 are both points to the native, but they are also cross-domain.
When the browser executes a JavaScript script, it checks which page the script belongs to and is not executed if it is not a homologous page.
Solution:
1, JSONP:
This is not the way to go, but note that JSONP only supports get requests and does not support post requests.
2. Agent:
For example www.123.com/index.html need to call www.456.com/server.php, you can write an interface www.123.com/server.php, which is called by this interface at the back end www.456.com/ Server.php and get the return value, and then return to Index.html, which is a proxy pattern. The equivalent of bypassing the browser side, naturally there is no cross-domain problem.
3, PHP side modified header (XHR2 way)
Add the following two sentences to the PHP interface script:
Header (' access-control-allow-origin:* ');//Allow all sources to access
Header (' Access-control-allow-method:post,get ');//The way to allow access