jquery Ajax combines thinkphp Getjson to implement Cross-domain methods _jquery

Source: Internet
Author: User

This article illustrates a cross-domain approach to the Getjson implementation of jquery Ajax combined with thinkphp. Share to everyone for your reference, specific as follows:

jquery in the post should not be cross-domain, the net said get can cross the domain, but I tried not to, and then on the final struggle Getjson, the results of success, haha

JS Office writing:

$.getjson (
    "/index.php/index/test",
    function (data) {
    alert (DATA.DD);
    }
);

Grammar:

Jquery.getjson (Url,[data],[callback])

Parameters Description
Url The URL address of the page to be loaded.
Data The Key/value parameter to be sent.
Callback The callback function that is executed when the load succeeds.

Writing at PHP:

$data [' dd ']= ' zonglonglong ';
$this->ajaxreturn ($data, ' JSON ');

This allows for cross-domain access.

If still not, hint homologous strategy problem, then in the server, PHP file, then write

Header ("access-control-allow-origin:*");

It means to support access to all other domains, and if you specify domain access, change the * number to a domain name, such as:

Header ("access-control-allow-origin:www.baidu.com");

More interested readers of jquery-related content can view the site: The summary of AJAX usage in jquery, the summary of jquery switching effects and techniques, the summary of jquery drag-and-drop effects and techniques, the summary of jquery extension techniques, jquery Common Classic Effects Summary "jquery animation and special effects usage Summary", "jquery selector usage Summary" and "jquery common Plug-ins and Usage summary"

I hope this article will help you with the jquery program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.