将请求放入Spring Boot Controller

我正在尝试将带有ajax的json字符串发送到我的spring boot控制器,但是我不断收到错误net :: ERR_TOO_MANY_REDIRECTS,并且在URL之后有很多$ csrfError。我看了无数其他网站和问题,但仍然无法正常工作。我如何正确设置我的ajax请求,以便我的控制器将接受数据?

我已经尝试将方法类型更改为post,并将RequestParams更改为ResponseBody,但是我回到了RequestParams

my ajax function
function deleteEvent() {
        var startTime = document.getElementById('newStartTime').value;
        var endTime = document.getElementById('newEndTime').value;
        var type = document.getElementById('newTimeOffType').value;
        var search = {startTime: startTime,endTime: endTime,type: type};
        if(confirm("Are you sure you want to delete this event?")){
            $.ajax({
                method: 'PUT',contentType: 'application/json',url: '/vacation/deleteEvents',dataType: 'json',data: JSON.stringify(search),success: function () {
                    console.log('success');
                },error: function (e) {
                    console.log(e);
                }
            })
        }
        else {
            alert('you said no')
        }

我的弹簧控制器

@RequestMapping(value = "/vacation/deleteEvents",method=RequestMethod.PUT)
@ResponseBody
public String deleteCalendarEvents(@RequestParam String startTime,@RequestParam String endTime,@RequestParam String type,HttpSession session ){
    User user = (User) session.getattribute("currentUser");
    System.out.println("startTime: " + startTime);
    System.out.println("endTime: " + endTime);
    System.out.println("type: " + type);
    return null;
}

我希望它打印出开始时间,结束时间并在控制台中键入,但是我一直收到此错误。

InitialQwertyJGW 回答:将请求放入Spring Boot Controller

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3142729.html

大家都在问