java解决ajax异步跨域问题

前端写法:

function qrCodeNameEdit(ajaxUrl,newName,storeId){
    $.ajax({
        type:'get',
        url : '/text',
        dataType : 'jsonp',
        jsonp:'callbackparam',
        success:function(json) {
            console.log(json);
        },
        error:function(e) {
            console.log(e);
        }
    });
}

重点在于:dataType使用jsonp   jsonp下定义callbackparam函数

后端写法:

@ResponseBody
@RequestMapping(value = "/text",method = RequestMethod.GET)
public JSONPObject text(HttpServletRequest request){
    String callbackparam = request.getParameter("callbackparam");
    boolean flag = channelCodeService.edit(newName);
    return new JSONPObject(callbackparam,flag);
}

猜你喜欢

转载自blog.csdn.net/qq_28582847/article/details/89327916
今日推荐