How to Use getJSON in JQuery _ jquery

Source: Internet
Author: User
There was a recent activity in which data needs to interact with pure static html websites. However, because the two websites are under different domain names, and Ajax applications, due to security issues, the browser does not support cross-origin calls by default, finally, we chose the getJSON method in JQuery. Here we use JSONP (JSON with Padding-filling json data, which is also a common json cross-domain method): we use the script tag to call it through a specific src address, to execute a client's js function, generate relative data (in JSON format) on the server side, and pass it as a parameter to the client's js function and execute this function, the premise is that data output from the server is supported. JSONP applications are supported after JQuery1.2.

JSON is a plain text that contains simple brackets. Therefore, many channels can exchange JSON messages. Because of the same-origin policy restrictions, we cannot use XMLHttpRequest when communicating with external servers. JSONP is a method that bypasses the same-origin policy. It uses the combination of JSON and script tags to directly return executable JavaScript function calls or JavaScript objects from the server.

Which of the following plays a key role in the entire call process?JSOncallback =?,When calling the client, you must add the parameter jsoncallback =? In the request address ?; At the same time, the server needs to pass back the jsoncallback value as the method name.

Server code:

The Code is as follows:


Protected void Page_Load (object sender, EventArgs e)
{
Response. Write (Request. QueryString ["jsoncallback"] + "({name: 'test '})");
}


Html page call:

The Code is as follows:




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.