The browser does not allow Ajax cross-site requests, so there is a cross-domain Ajax problem, there are two main ways to solve.
1. Use the Access-control-allow-origin header on the request page.
All site requests can be accepted using the following headers:
Header (' access-control-allow-origin:* ')
Use the following header to accept the specified Web request:
Header (' access-control-allow-origin:http://www.abc.com ')
So, the server notation:
Header (' access-control-allow-origin:* '); Die (Json_encode (' msg ' = ' msg ..... '));
The AJAX notation is the same as usual:
<! DOCTYPE html>
2. Use JSONP cross-domain requests.
Server:
$data = Json_encode (' msg ' = ' msg ... ');d ie ($_request[' function_name_index '). ' ('. $data. ') ' );
Ajax requests:
<! DOCTYPE html>
In the AJAX request, the use of the JSONP data format, so the datatype parameter is set to JSONP, usually, also added to the Jsonp and jsonpcallback two parameters, combined with code, it is not difficult to see these two parameters function:
The role of the JSONP is to set the server to get the callback function name parameter subscript parameter, Jsonpcallback function is to set the callback functions, equivalent to the input tag name and VALUE,JSONP corresponding name,value corresponding jsonpcallback.
More Jsonp request can refer to: http://www.cnblogs.com/duanhuajian/p/3152617.html, there is a very detailed introduction to the principle.
Of course, for some simple get requests, Ping does not need a callback function processing, you can use the script, IMG, iframe and other HTML tags set the SRC attribute to generate a GET request, here is not discussing the situation.
Source: http://www.cnblogs.com/pandang/
Two solutions to Ajax cross-domain problems