jquery 前端 跨域 jsonp
Posted hoge
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery 前端 跨域 jsonp相关的知识,希望对你有一定的参考价值。
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(); }
以上是关于jquery 前端 跨域 jsonp的主要内容,如果未能解决你的问题,请参考以下文章