jquery ajax combined with thinkphp's getjson to achieve cross-domain method
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
