ajax的POST方法使用

前端js代码:

        var msg= $("#test").val();
        $.ajax({
            async : false,
            type: "post",
            url: "/push/",
            contentType:'application/json;charset=UTF-8',
            data: msg,
            error : function(request) {
            },
            success : function(data) {
                alert(data.code);
            }
        });

 

controller层代码

 

    @RequestMapping(value = "push", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject pushMessage(@RequestBody String msg){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",0);
        return jsonObject;
    }

 

posted @ 2020-11-19 17:35  韋大脸  阅读(3207)  评论(0编辑  收藏  举报