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
- var url = "${bipjs}/intf/accountsofrefuseemail.jsp?act=add&siteid=${lang.siteid}&accountid=${loginid} &callback=? ";
- $.getjson (URL, {}, function (data) {
- var code = Data.code;
- if (code = = 0) {
- $ (' #floatOne '). Myfadein ();
- }
- });
The data returned is a JSON object, and accordingly, the server returns the string to be of this style:
Java code
- String callback = T.stringvalue (Getrequestparams (Request,"callback"), "");
- Jsonobject Jo = new Jsonobject ();
- Put Key/value in Jo
- 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:
- 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