用java spring禁止Ajax删除请求

时间:2013-12-08 23:35:23

标签: java jquery ajax spring spring-mvc

我正在尝试向java spring发送删除请求。问题是我总是收到403禁止响应消息。

这是客户端的javascript代码:

$(".deleteList").click(function(){
        var url = "boodschappenlijstjes.htm/" + this.id;
        console.log(url);
        $.ajax(url, {
            method: "DELETE",
            success: function(){
                console.log("gelukt");
            }
        });
    });

我正在尝试访问的控制器方法:

    @RequestMapping(value = "/boodschappenlijstjes/{id}", method = RequestMethod.DELETE)
    public ResponseEntity verwijderLijstje(Principal principal, @PathVariable(value="id") int id)
    {
        //some code
    }

我也在使用spring security:

    <http auto-config = "true">
        <intercept-url pattern='/overzicht*' access='ROLE_USER' />
        <intercept-url pattern='/klant*' access='ROLE_USER' />
        <intercept-url pattern='/boodschappenlijstjes*' access='ROLE_USER' />
        <form-login login-page="/login.htm"
                    default-target-url="/overzicht.htm" 
                    authentication-failure-url="/loginfailed.htm" />
        <logout logout-success-url="/logout.htm" />
    </http>

我希望有人可以帮助我...

THX

2 个答案:

答案 0 :(得分:0)

$.ajax({
        url: url,
        method: "DELETE",
        success: function(){
            console.log("gelukt");
        }
    });

答案 1 :(得分:0)

我找到了解决方案:我必须将javascript文件中的url更改为:

"boodschappenlijstjes/" + this.id + ".htm"