码迷,mamicode.com
首页 > Web开发 > 详细

jquery 前端 跨域 jsonp

时间:2019-02-23 13:34:22      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:produces   jquery   addheader   charset   支持   utf-8   增加   cal   highlight   

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

标签:produces   jquery   addheader   charset   支持   utf-8   增加   cal   highlight   

原文地址:https://www.cnblogs.com/hoge66/p/10422358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!