jquery ajax combined with thinkphp's getjson to achieve cross-domain method
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:
$.getJSON( "/index.php/Index/test", function(data){ alert(data.dd); } );
Syntax:
jQuery.getJSON(url,[data],[callback])
PHP writing:
$data['dd']='zonglonglong'; $this->ajaxReturn($data,'JSON');
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
header("access-control-allow-origin:*");
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:
header("access-control-allow-origin:www.baidu.com");
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!

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)

Hot Topics



