String result=request.getParameter("data")==null?"null":request.getParameter("data");
String callback = request.getParameter("jsonpCallback")+"([{\"results\":"+result+"}])";
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.getWriter().write(callback);
response.getWriter().flush();
response.getWriter().close();
System.out.println("json:"+callback+"接收返回");
客户端test.html
$.getJSON("http://10.100.121.113:8081/test.jsp?jsonpCallback=?&data=90", function(data){
alert(data[0].results);
});
jQuery JSONP跨域
最新推荐文章于 2023-06-06 11:58:16 发布