HTTP接口-跨域-callback

时间:2023-03-08 17:38:53
HTTP接口-跨域-callback

1.客户端和正常调用非跨域接口一样
2.服务端
返回的时候用callback+(返回值)的方式返回结果. callback为客户端的隐藏参数.
public String converJsonResultSimple(String jsonString ,String callback){
if(callback!=null && !"".equals(callback)){
jsonString = callback + "(" + jsonString + ")";
}
return jsonString;
}
@RequestMapping(value = "/uploadUserBehaviorInfo", method = {RequestMethod.GET,RequestMethod.POST})
public String uploadUserBehaviorInfo(String data,String callback){
Sting resutStr = data+"处理结果";
return converJsonResultSimple(resutStr,callback);
}