/**html文件*/
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery EasyUI</title>
<script type="text/javascript" src="../jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function() {
$("#button1").click(function() {
alert("gagag");
var url="http://192.168.1.155:8080/jml/pos/test.fbi";
$.getJSON(url + "?callback=?", function(json) {
alert(json.name);
});
});
});
</script>
</head>
<input value="button" type="button" id="button1"/>
<body></body>
</html>
/**后台文件*/
/**格式要求:
在服务端通过获得callback参数(如下:value="jsonp*****")得到jQuery端随后要回调的
然后返回类似:"jsonp*****("+要返回的json对象+")";
*/
@RequestMapping(value = "/jml/pos/test.fbi")
public void testRequest(final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
final String jsonp = request.getParameter("callback");
response.setContentType("text/html; charset=utf-8");
response.setCharacterEncoding("utf-8");
response.getWriter().print(jsonp+"({\"name\":\"yoyo!\"})");
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery EasyUI</title>
<script type="text/javascript" src="../jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function() {
$("#button1").click(function() {
alert("gagag");
var url="http://192.168.1.155:8080/jml/pos/test.fbi";
$.getJSON(url + "?callback=?", function(json) {
alert(json.name);
});
});
});
</script>
</head>
<input value="button" type="button" id="button1"/>
<body></body>
</html>
/**后台文件*/
/**格式要求:
在服务端通过获得callback参数(如下:value="jsonp*****")得到jQuery端随后要回调的
然后返回类似:"jsonp*****("+要返回的json对象+")";
*/
@RequestMapping(value = "/jml/pos/test.fbi")
public void testRequest(final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
final String jsonp = request.getParameter("callback");
response.setContentType("text/html; charset=utf-8");
response.setCharacterEncoding("utf-8");
response.getWriter().print(jsonp+"({\"name\":\"yoyo!\"})");
}