需要用到GeoServer REST下的delete接口,使用ajax type=“DELETE”,总是被403Forbidden,最后发现表单竟然能成功。查看表单的提交参数,发现表单竟然是用POST请求,并在请求中添加了_method='delete’的参数。效仿其做法,ajax的请求也成功了。
成功的ajax delete请求:
$.ajax({
type:"POST",
data:{_method:'delete'},
url:"URL",
success:function(){
console.log("success");
},
error:function(){
console.log("error");
}
});
失败了的ajax delete请求
$ajax({
type:"DELETE",
url:"URL",
success:function(){
console.log("success");
},
error:function(){
console.log("error");
}
})
同理,按照成功的例子ajax来发送put请求应该也没问题,但是我还没有试验过。