此脚本(在浏览器中执行):
$(function(){
$.ajax("http://localhost:3000/rest/room/7", {
type: "DELETE",
success: function(data, statusText, jqXHR){
$("p").text("complete, " + statusText + ", " + data.status + " data=" + JSON.stringify(data) + " jqXHR=" + JSON.stringify(jqXHR));
},
complete: function(data, statusText, jqXHR){
$("p").text("complete, " + statusText + ", " + data.status + " data=" + JSON.stringify(data) + " jqXHR=" + JSON.stringify(jqXHR));
}
});
});
而这条 Express 路线定义:
app.delete('/rest/room/:id', function(req, res){
res.json(JSON.stringify(findings[0]));
});
只是在浏览器中得到这个:
complete, error, 404 data={"readyState":4,"status":404,"statusText":"error"} jqXHR=undefined
和这个控制台输出(使用 PhpStorm IDE):
OPTIONS /rest/room/7 200 1ms - 4.51kb
为什么“DELETE”请求会变成“OPTIONS”请求?我错过了什么?