跨域请求
var ticket = $.cookie("token");
$.ajax{ url:"http://localhost:8088/user/token" + ticket, datatype:"jsonp", type:"GET", success: function(data){ console.info(data); } } @RequsetMapping(value="/user/token/{token}", produces=MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public String getUserByToken(@PathVariable String token, String callback){ if(callback != null) {
//第一种方式 return callback + "{"+JsonUtils.objectToJson(res)+"}";
//第二种方式
MappingJacksonValue jackon = new MappingJacksonValue(res);
jackson.setJsonpFunction(callback);
return jackson;
} else {
return res;
}
}