我有一個API,如果需要更新對象,我應該發送PATCH請求;問題是,當我發送PATCH請求身體總是未定義。NodeJS:如何使用HTML表單發送PATCH&DELETE請求
這是如何我發送PATCH請求例如。
app.patch('/applications/update/:application_id', function(request, response) {
var application_id = request.params.application_id;
require('../../models/applications/update_application_by_id').get(request.body, application_id, function(result){
response.render('applications/details', {application_details:result});
});
});
<form enctype="application/json" class="form-horizontal" role="form" method="post" action="/applications/update/{{application_details._id}}">
<input type="hidden" name="_method" value="PATCH" />
<input type="text" name="name" class="form-control">
<button type="submit" class="btn btn-yellow pull-right">update</button>
</form>
,這我如何處理它
exports.get = function(request_body, application_id, call_back){
var http_request = unirest("patch", "https://xx/api/applications/"+application_id);
http_request.headers({
"cache-control": "no-cache",
"content-type": "application/json",
"x-application-key": "xxxxxxxxxxxxxxxxxx"
});
http_request.type("json");
http_request.send(request_body);
http_request.end(function (http_response) {
console.log(http_request.body);
if (http_response.error) throw new Error(http_response.error);
return call_back(http_response.body);
});
}
我已經添加 裏面的表格,仍然不能工作 –
如果你沒有明確處理y ou on。 ExpressJS **不會爲你做這件事。 – kazenorin