Js:
<script type= "Text/javascript" >
function jsonpcallback (result) {
alert (result[1].name);
}
</script>
<script type= "Text/javascript" src= "http://localhost:8080/Jsonp/jsonp.jsp?callback= Jsonpcallback "></script>
or jquery:
<script type= "Text/javascript" >
$.getjson ("http://localhost:8080/Jsonp/jsonp.jsp?callback=?", function (JSON) {
alert (json[0].name);
});
</script>
jsonp.jsp
<%
String callback = Request.getparameter ("callback");
Out.print (callback+) ([{name: ' John ', Age: '},{' name: ' Joe ', Age: '}]; ");
Out.print (callback);
%>
The background can be implemented with action or servlet.
Finally, as long as the browser input http://localhost:8080/Jsonp/test.jsp will pop up John.
See: http://blog.csdn.net/alen1985/article/details/6365394
Jsonp instance http://blog.csdn.net/aabbcc456aa/article/details/18559987
JSONP Call and background Java return http://blog.csdn.net/z69183787/article/details/15809167