1. 程式人生 > >ajax跨域

ajax跨域

.com ajax跨域 eat create ebo amp mapping local ble

/**
     * 需求:根據token查詢redis服務器用戶身份信息
     * 請求:http://localhost:8088/user/token/" + _ticket??callback=jQuery2795009&_=1506226664795
     * 參數:String token
     * 返回值:E3mallResult
     * {
        status: 200
        msg: "OK"
        data: "{"id":1,"username":"zhangzhijun","phone":"15800807944",
        "email":"[email protected]","created":1414119176000,"updated":1414119179000}"
      }

     */
    @RequestMapping("/user/token/{token}")
    @ResponseBody
    public Object findRedisWithToken(@PathVariable String token,String callback){
        //調用遠程service對象方法
        E3mallResult result = userService.findRedisWithToken(token);
        //判斷是否跨域請求
        if(StringUtils.isBlank(callback)){            
            //返回
            return result;
        }
        //否則就是跨域請求
        //return "callback("++")"
        //使用Jackson自動支持ajax跨域數據轉換
        MappingJacksonValue jacksonValue = new MappingJacksonValue(result);
        //設置回調函數
        jacksonValue.setJsonpFunction(callback);
        
        return jacksonValue;
    }

ajax跨域