本文介绍了Connect.js methodOverride有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Connect.js 非常简洁的文档methodOverride

The Connect.js very terse documentation says methodOverride

那是什么意思? 远没有帮助.为什么methodOverride有用?

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

推荐答案

  • 如果要模拟DELETEPUT,请使用methodOverride.
  • 如果传入设置为'delete''put'的_method post参数,则可以在Express中使用app.deleteapp.put代替一直使用app.post(因此更具描述性,冗长):
    • 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):
    • 后端:

      // 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>
      

      这篇关于Connect.js methodOverride有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:28