• jsonp使用


    jsp页面:

    $.ajax({
    type:"get",
    dataType:"jsonp",
    url: http://www.cgh.com:9091/cmis-web2/cookie/setCookie.do?cookieVal=dgrr556fghjcvn56667889hkdbj,
    jsonp: 'callback',
    crossDomain:true,
    success: function(data){
       alert(data.code);
    },
    beforeSend:function(){
    },
    complete:function(data,status){
    },
    error:function(){
    alert("system error!");
    }
    });

    后台接收:

    @Controller
    @RequestMapping("cookie")
    public class CookieSetController {
    @RequestMapping(value = "setCookie.do")
    public @ResponseBody String setCookie(HttpServletRequest request, HttpServletResponse response,
    @RequestParam(value = "cookieVal") String cookieVal,String callback) {
    ResultModel resultModel = new ResultModel();
    try {
    response.addHeader("P3P", "CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR");
    Cookie cookie = new Cookie(ComContants.CK_SESSIONID, cookieVal);
    cookie.setPath("/");
    response.addCookie(cookie);
    resultModel.setCodeToSuccessed();

    } catch (Exception e) {
    e.printStackTrace();
    resultModel.setCode(ResultModel.ERROR_CODE, e.getMessage());
    }
    return callback+"("+JsonConvert.toJSON(resultModel)+")";
    }

    }

  • 相关阅读:
    当老板如何带团队?
    创业者第一法宝-了解自己
    交流才能交易,交易才能交心
    集合框架
    MySQL一些命令语法
    JS组成整理
    git中可以pull但是push提示Everything up-to-date的情况
    循环判断以及文件的使用--练习1
    Hello World !
    linux文件权限修改
  • 原文地址:https://www.cnblogs.com/cghhnty/p/7665762.html
Copyright © 2020-2023  润新知