This article describes the cross-domain method of jquery ajax combined with thinkphp's getjson implementation. Share it for your reference, as follows:
The post in jquery should not be cross-domain. The internet says that get can cross-domain, but I tried it but couldn't. Then I made the final struggle to getjson, and the result was successful, haha
Writing at js:
$.getJSON( "//Index/test", function(data){ alert(); } );
grammar:
(url,[data],[callback])
parameter | describe |
---|---|
url | The URL address of the page to be loaded. |
data | Key / value parameters to be sent. |
callback | A callback function executed when the load is successful. |
Writing at php:
$data['dd']='zonglonglong'; $this->ajaxReturn($data,'JSON');
This allows cross-domain access.
If it still doesn't work, it prompts a problem with the same-origin policy. Then, if it is on the server, the php file, please write it on
header("access-control-allow-origin:*");
It means to support access to all other domains. If it is accessed by a specified domain, change the * number to the domain name, such as:
header("access-control-allow-origin:");
For more information about jQuery, please visit the special topic of this site:Summary of Ajax usage in jquery》、《Summary of jQuery switching effects and skills》、《Summary of jQuery drag and drop special effects and skills》、《Summary of jQuery extension skills》、《Summary of common classic effects of jQuery》、《Summary of jQuery animation and special effects usage》、《Summary of jquery selector usage"and"Summary of commonly used plug-ins and usages of jQuery》
I hope this article will be helpful to everyone's jQuery programming.