The example of this article describes the method of combining jquery ajax with thinkphp's getjson to achieve cross-domain. Share it with everyone for your reference, the details are as follows:
The post in jquery should not be cross-domain. It is said on the Internet that the get can be cross-domain, but I tried it but it didn’t work, and then I made the final effort to getjson. The result was successful, haha
js writing:
$.getJSON( "/index.php/Index/test", function(data){ alert(data.dd); } );
Syntax:
jQuery.getJSON(url,[data],[callback])
Writing at php:
$data['dd']='zonglonglong'; $this->ajaxReturn($data,'JSON');
This way you can access across domains.
If it still doesn’t work, it prompts a problem with the same origin policy, then on the server side, in the php file, write
header("access-control-allow-origin:*");
means Supports access from all other domains. If it is a designated domain access, change the * number to the domain name, such as:
header("access-control-allow-origin:www.baidu.com");
I hope this article will help everyone jQuery program Design helps.
For more related articles on jquery ajax combined with thinkphp’s getjson to achieve cross-domain methods, please pay attention to the PHP Chinese website!