Callback Description of the $.getjson () method

Source: Internet
Author: User

The $.getjson () method crosses the domain to get the JSON object of the server, the suffix of the URL finally takes a "callback=?" Parameters as a successful callback function, such as:

JS Code
  1. var url = "${bipjs}/intf/accountsofrefuseemail.jsp?act=add&siteid=${lang.siteid}&accountid=${loginid} &callback=? ";
  2. $.getjson (URL, {}, function (data) {
  3. var code = Data.code;
  4. if (code = = 0) {
  5. $ (' #floatOne '). Myfadein ();
  6. }
  7. });

The data returned is a JSON object, and accordingly, the server returns the string to be of this style:

Java code
    1. String callback = T.stringvalue (Getrequestparams (Request,"callback"), "");
    2. Jsonobject Jo = new Jsonobject ();
    3. Put Key/value in Jo
    4. Out.print (callback + "(" + Jo + ")");

Principle: jquery automatically generates a callback=jsonp*** string when parsing the request callback=, which jsonp*** as a method at the time of the successful callback and is automatically executed by Jquey. The parameter is a JSON-formatted string (here is data). Accordingly, the string returned by the server is in this form: jsonp*** (jsonobject).

Such as: Just above the URL is jquey parsed into:

    1. Request url:http://localhost.pcauto.com.cn:12385/intf/accountsofrefuseemail.jsp?act=add&siteid=2& accountid=388&callback=jsonp1381976698163&_=1381976708919

The string form returned by the server:

jsonp1381976698163 ({"code":0,"msg":"Increase user Success"})

The jquery callback method jsonp1381976698163 (JSONSTR) is to convert the string jsonstr to a Josn object, and here is the JSON object converted to data.

Callback Description of the $.getjson () method

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.