Home >Web Front-end >JS Tutorial >How to use getJSON in JQuery_jquery
JSONP (JSON with Padding - filling json data, which is the commonly used json cross-domain method) is used here: using the script tag and calling a specific src address to execute a client-side js function and generate relative data on the server side ( JSON format) and pass it to the client's js function in the form of parameters and execute this function, provided that the server-side data output support is required. JSONP applications are supported after JQuery 1.2.
JSON is plain text with a simple bracket structure, so 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 can bypass the same-origin policy, that is, by using JSON combined with the <script> tag to directly return executable JavaScript function calls or JavaScript objects from the server. </span></p>
<p><span style="FONT-FAMILY: 宋体"></span> The key role in the entire calling process is <span style="COLOR: #ff0000">j</span><font face="Verdana"><span style="COLOR: #ff0000">s</span><span style="COLOR: #ff0000">oncallback=?</span></font>,When calling on the client, you need to add parameters to the request address: jsoncallback=?; at the same time, the server needs to pass the value of jsoncallback back as the method name. </p>
<p><span style="FONT-FAMILY: 宋体"></span><span style="FONT-FAMILY: 宋体"> Server code: <br><div class="codetitle">
<span><a style="CURSOR: pointer" data="37003" class="copybut" id="copybut37003" onclick="doCopy('code37003')"><u>Copy code</u></a></span> The code is as follows: </div>
<div class="codebody" id="code37003"> <br>protected void Page_Load(object sender, EventArgs e) <br>{ <br>Response.Write(Request.QueryString["jsoncallback"] "({name:'test'})"); <br>} <br>
</div> <br>html page call: <br><div class="codetitle">
<span><a style="CURSOR: pointer" data="28717" class="copybut" id="copybut28717" onclick="doCopy('code28717')"><u>Copy code </u></a></span> The code is as follows: </div>
<div class="codebody" id="code28717"> <br><html xmlns="http://www.w3.org/1999/xhtml" > <br><head > <br><script type="text/javascript" src="jquery-1.4 .4.js"></script>
< /div>