首页 > 代码库 > jquery发送json请求,给springmvc接收

jquery发送json请求,给springmvc接收

js

                var obj = {
                    ‘name‘:name,
                    ‘desc‘:desc,
                    ‘scheduleStartTime‘:scheduleStartTime,
                    ‘scheduleEndTime‘:scheduleEndTime
                };
                $.ajax({
                    url: "../task/insert",
                    type: "post",
                    contentType:"application/json;charset=UTF-8",
                    data: JSON.stringify(obj),
                    success: function (result) {
                        alert(result);
                    }
                });

  

controller

    @RequestMapping(value = "http://www.mamicode.com/insert",method = RequestMethod.POST,consumes = "application/json")
    public String insert(@RequestBody Task task){
        System.out.println("task = " + task);
        return null;
    }

  

jquery发送json请求,给springmvc接收