Analysis of mobile development jsonp and development of jsonp
Principle: The content output by the server is equivalent to calling the client functions and loading data of different domains using callback.
Server script
Header ('content-type: application/json ');
// Obtain the callback function name
$ Jsoncallback = htmlspecialchars ($ _ REQUEST ['jsoncallback']);
// Json data
$ Json_data = '["mermername1", "customername2"]';
// Output data in jsonp format
Echo $ jsoncallback. "(". $ json_data .")";
?>
Client script
<Meta charset = "UTF-8"> <title> JSONP instance </title> <p id = "pCustomers"> </p> <script type = "text/javascript"> function callbackFunction (result, methodName) {var html = '<ul>'; for (var I = 0; I <result. length; I ++) {html + = '<li>' + result [I] + '</li>';} html + = '</ul> '; document. getElementById ('pcustomers '). innerHTML = html ;}</script> <script type = "text/javascript" src = "https: // localhost/test. php? Jsoncallback = callbackFunction "> </script>