The example in this article describes the method of using jquery ajax combined with thinkphp's getjson to achieve cross-domain. I share it with you for your reference. The details are as follows:
Post in jquery should not be cross-domain. It is said on the Internet that get can be cross-domain, but I tried it but it didn’t work. Then I tried my best to getjson and the result was successful, haha
JS writing:
1 2 3 4 5 6 |
|
Syntax:
jQuery.getJSON(url,[data],[callback])
PHP writing:
1 2 |
|
This way it can be cross-domain Visited.
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
1 |
|
means to support access from all other domains. If it is a specified domain access, put * Change the number to a domain name, such as:
1 |
|
I hope this article will be helpful to everyone in jQuery programming.
For more related articles on how to implement cross-domain methods using jquery ajax combined with thinkphp’s getjson, please pay attention to the PHP Chinese website!