Jquery + ajax + jsonp for cross-origin requests

Source: Internet
Author: User
A previous blog detailed the jsonp protocol. jqueryajax encapsulates the jsonp Protocol to make cross-origin request implementation so simple: $. ajax ({type: & quot; post & quot ;,

A previous blog detailed the jsonp protocol. jquery ajax encapsulates the jsonp Protocol, making cross-origin request implementation so simple:

$. Ajax ({type: "post", url: "http://www.phpddt.com/ajax/test", dataType: "jsonp", jsonp: "callback", // to the request handler or page, the parameter name used to obtain the jsonp callback function name (default: callback) jsonpCallback: "success_jsonpCallback", // The Custom jsonp callback function name, the default value is the random function name success: function (json) {alert ('success ') ;}, error: function () automatically generated by jQuery () {alert ('fail ');}});

The server process is as follows:
$ Data = ....... $ callback = $ _ GET ['callback']; echo $ callback. '('. json_encode ($ data ). ')'; exit;

When jsonp is used and JSONP is used to call a function, for example, "myurl? Callback =? "Will jQuery be replaced automatically? For the correct function name to execute the callback function.

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.