html按钮可以执行POST请求吗? [英] Can a html button perform a POST request?

查看:999
本文介绍了html按钮可以执行POST请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望提交类型按钮发送POST请求.

I want a submit type button to send a POST request.

我正在考虑这样的事情:

I am thinking about something like this:

<form action = "" method = "post">
    <button>Upvote</button>
<form>

在POST请求中将字符串"Upvote"作为名称发送.

where the string "Upvote" will be send as a name in the POST request.

我知道这是行不通的,并且我知道有使用AJAX(javascript)的方法,但是我在这个领域还很陌生.我只是想知道这是否可能.

I know this is not working, and I know there are ways using AJAX(javascript) but I am fairly new to this area. I am just wondering if this is possible in general.

更新

有人建议我使用<input>标记.问题在于它生成的是GET而不是POST.

Someone suggest that using <input> tag, I used it. The problem is it generate a GET rather than a POST.

推荐答案

这可以通过类型为"submit"的输入元素来完成.这将对用户显示为按钮,单击该按钮将发送表单.

This can be done with an input element of a type "submit". This will appear as a button to the user and clicking the button will send the form.

<form action="" method="post">
    <input type="submit" name="upvote" value="Upvote" />
</form>

这篇关于html按钮可以执行POST请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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