A Brief Introduction to ajax cross-origin requests and a brief introduction to ajax

Source: Internet
Author: User

A Brief Introduction to ajax cross-origin requests and a brief introduction to ajax

A Brief Introduction to ajax cross-origin requests:
This chapter describes ajax cross-origin requests. The content mainly refers to an article on the internet, hoping to help you.
1. jsonp format file:
If the obtained data file is stored on a remote server (the domain name is different, that is, cross-Origin data retrieval), The jsonp type is required. If this type is used, a query string parameter callback =? will be created? This parameter is added after the request URL. The server should add the callback function name before the JSON data to complete a valid JSONP request. This means that the remote server needs to process the returned data and return a callback (json) data according to the callback parameter submitted by the client, the client will process the returned data in script Mode to process json data. JQuery. getJSON also supports jsonp data calling.
Ii. Sample Code for calling the client JQuery. ajax:

 

$. Ajax ({type: "get", async: false, url: "http://www.softwhy.com/ajax.do", dataType: "jsonp", jsonp: "callbackparam ", // The parameter jsonpCallback of the function name used by the server to receive callback calls: "success_jsonpCallback", // The function name success of callback: function (json) {alert (json ); alert (json [0]. name) ;}, error: function () {alert ('fail ');}});

 

Iii. Sample Code returned by the server:

public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; String callbackFunName = context.Request["callbackparam"]; context.Response.Write(callbackFunName + "([ { name:\"John\"}])"); }

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 8131.

For more information, see: http://www.softwhy.com/jquery/

 

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.