What does Connect.js methodOverride do?

試著忘記壹切 提交于 2019-11-30 06:10:09

问题


The Connect.js very terse documentation says methodOverride

Provides faux HTTP method support.

What does that mean? The obvious Google search is less than helpful. Why is methodOverride useful?


回答1:


  • If you want to simulate DELETE and PUT, methodOverride is for that.
  • If you pass in the _method post parameter set to 'delete' or 'put', then you can use app.delete and app.put in Express instead of using app.post all the time (thus more descriptive, verbose):

Backend:

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

Client logic:

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


来源:https://stackoverflow.com/questions/8378338/what-does-connect-js-methodoverride-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!