Connect.js methodOverride有什么作用?


116

Connect.js 非常简洁的文档methodOverride

提供伪HTTP方法支持。

那是什么意思?在明显的谷歌搜索不到有帮助的。为什么methodOverride有用?


3
等等,那不是明显的谷歌搜索。那将是“ Connect.js methodoverride”或“ Connect javascript methodoverride”。没有任何理由认为“伪HTTP”是某种标准。大约在2013年3月3日发行的第一集与Kim Kardashian有关。
djechlin

1
也许Kardashian女士有节点柔术?:)
Umar Farooq Khawaja

3
“假”表示“假”,“假”或“模拟”。
彼得·伍德

Answers:


147
  • 如果要模拟DELETEPUTmethodOverride则为此。
  • 如果您将_method post参数设置为'delete''put',则可以在Express中使用app.deleteand app.put而不是一直使用app.post(因此更具描述性,冗长):

后端:

// the app
app.put('/users/:id', function (req, res, next) {
  // edit your user here
});

客户端逻辑:

// client side must be..
<form> ...
  <input type="hidden" name="_method" value="put" />
</form>

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.