@RequestMapping(value="/getOneCategory" )
public String getOneCategory(HttpServletRequest request,HttpServletResponse response) {
Map<String,String> map = new HashMap<String,String>();
map.put("name", "老李");
map.put("age", "23");
String string=JSON.toJSONString(map);
String jsonpCallback = request.getParameter("jsonpCallback");//客户端请求参数
String json=jsonpCallback+"("+string+")";
return json;
}
$.ajax({
type:"post",
url: "http://127.0.0.1:8080/ssm/getOneCategory",
data:{"nn":1223},
dataType: 'jsonp',
jsonp: "jsonpCallback",//服务端接收jsonpCallback,用来拼接返回数据
contentType : "application/json;charset=UTF-8",
success: function(result){
console.log(result);
}
});