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: