Ajax Cross-domain Access is an old problem, there are many solutions, more commonly used is the Jsonp method, the Jsonp method is an unofficial method, and this method only supports get way, not as safe as post method.
Even if you use the Jsonp method of jquery, type is set to post and automatically becomes get.
Official Problem Description:
"Script": evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, ' _=[timestamp] ', to the URL unless the cache option is set to True . Note:this'll turn POSTs into GETs for Remote-domain requests.
If you use the Post method across domains, you can use the Create a hidden iframe to do the same as the Ajax upload picture principle, but this will be more cumbersome.
Therefore, it is simpler to implement Cross-domain access by setting Access-control-allow-origin.
For example: The domain name of the client is www.client.com, and the requested domain name is www.server.com
If you use AJAX access directly, you will have the following error
XMLHttpRequest cannot load http://www.server.com/server.php. No ' Access-control-allow-origin ' header is present on the requested resource. Origin ' http://www.client.com ' is therefore not allowed access.
join in the requested response header
[PHP] view Plain copy//Specify allow other domain name Access header (' access-control-allow-origin:* '); Response Type header (' Access-control-allow-methods:post '); Response header Set header (' Access-control-allow-headers:x-requested-with,content-type ');
You can implement Ajax post Cross-domain access.
The code is as follows:
client.html Path: http://www.client.com/client.html
[HTML] View Plain copy <! doctype html public "-//w3c//dtd html 4.0 transitional//en" > < html> server.phpPath: http://www.server.com/server.php
[PHP] view plain copy