jquery 前端 跨域 jsonp

时间:2023-12-21 22:31:56

1、jsonp 支持get;可以跨域;

2、java 在controller中增加header:

 /**
* 获取用户信息
*/
@ResponseBody
@RequestMapping(value = "/user/getuserInfo", method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
public String getUserInfo(@RequestParam Map<String, Object> paramMap, HttpServletRequest request
, HttpServletResponse response) {
// response.addHeader("Access-Control-Allow-origin","localhost");
response.addHeader("Access-Control-Allow-Credentials","true");
response.addHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS,PUT,DELETE");
response.addHeader("Access-Control-Allow-Headers","cache-control,content-type,hash-referer,x-requested-with");
log.info("get the /user/getInfo request data : " + paramMap.get("userId").toString());
JsonResultEx result = new JsonResultEx(); String username = paramMap.get("userId").toString();
}