当我尝试在 Express 中执行 PUT 请求时,它给了我这个错误,我不确定这意味着什么。
这是我的玉:
extends layout
block content
form(method="post" action="/meals/#{meal[0].id}", id="mealForm")
input(type="hidden", name="_method", value="PUT")
h4 Meal Type
input.span3(id="mealType", type="text", name="MealType", value="#{meal[0].meal_type}")
br
h4 Meal Details
input.span3(id="mealDetails", type="text", name="MealDetails", value="#{meal[0].meal_details}")
br
input.btn(type="submit", class="btn btn-primary btn-lg" value="Update")
form(method="post" action="/meals/#{meal[0].meal_id}", id="mealForm")
input(type="hidden", name="_method", value="DELETE")
input.btn(type="submit", class="btn btn-danger btn-lg" style='margin-left: 1px;' value="Delete")
我不明白为什么这行不通。这是我的 app.js:
app.put('/meals/:id', meal.getMeal)
在饭菜.js
exports.getMeal = function(req, res){
console.log('sa')
id = req.params.id
query = "Select * \
From nutrition \
Where id=%"
query = query.replace(/%/g, id)
db.query(query, function(err, row) {
console.log(query);
if (err) console.log(err)
res.render('edit', { meal: row });
})
}
堆栈跟踪:
500 TypeError: Object PUT,DELETE has no method 'toLowerCase'
at Object.methodOverride [as handle] (\middleware\methodOverride.js:37:30)