The JSON data format uses the server and client code, and the json Server
JSON Application 1. Server JSONP format data
Assume that the customer expects to return JSON data: ["mermername1", "customername2"].
The data actually returned to the client is displayed as callbackFunction (["mermername1", "customername2"]).
The jsonp. php code of the Server File is:
1 <? Php2 header ('content-type: application/json'); 3 // obtain the callback function name 4 $ jsoncallback = htmlspecialchars ($ _ REQUEST ['jsoncallback']); 5 // json data 6 $ json_data = '["customername1", "customername2"]'; 7 // output data in jsonp format 8 echo $ jsoncallback. "(". $ json_data. ")"; 9?>CallbackFunction implemented by the client
1 <script type = "text/javascript"> 2 function callbackFunction (result, methodName) 3 {4 var html = '<ul>'; 5 for (var I = 0; I <result. length; I ++) 6 {7 html + = '<li>' + result [I] + '</li> '; 8} 9 html + = '</ul>'; 10 document. getElementById ('vcustomer '). innerHTML = html; 11}
More references: http://www.iplaypy.com/json/