expressjs支持方法删除和放置没有methodoverride [英] expressjs support for method delete and put without the methodoverride

查看:89
本文介绍了expressjs支持方法删除和放置没有methodoverride的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取expressjs使用表单的删除和放置方法?

How do i get expressjs to use the delete and put methods for form?

<form method="DELETE" action="">

使用上述方法是在最新的稳定版本的chrome中发送GET请求。这是否应该是一个浏览器问题?

Using the above is sending a GET request in latest stable version of chrome. Is this supposed to be a browser issue?

有没有更好的方法来覆盖这个没有一个特殊的输入字段支持这些?

Is there a better way to override this without having a special input field for supporting these?

推荐答案

您只需要设置表单发布,然后创建一个隐藏的字段,如

You just need to set the form to post, then create a hidden field like

<input type="hidden" name="_method" value="delete"/>

根据您正在使用的快速版本设置配置。那么表单方法将被该隐藏字段的值覆盖。

And set the configuration, according to the express version you are using. Then the form method will be overridden by the value of that hidden field.

最新版本的 express.js 将要求您安装方法覆盖包,然后如下配置您的应用程序:

The latest version of express.js will require you to install the method-override package, then configure your app like this:

var methodOverride = require('method-override')
app.use(methodOverride('_method'));

旧版本可能使用:

app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(express.methodOverride());

较旧的用法是:

app.use(express.bodyParser());
app.use(express.methodOverride());

这篇关于expressjs支持方法删除和放置没有methodoverride的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆