HTML 按钮可以执行 POST 请求吗? [英] Can a HTML button perform a POST request?
问题描述
我想要一个提交类型的按钮来发送 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>
其中字符串Upvote"将作为 POST 请求中的名称发送.
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.
更新
有人建议使用 标签,我试过了.问题是它生成的是 GET 而不是 POST.
Someone suggested using the <input>
tag, and I tried it. The problem is it generates a GET rather than a POST.
推荐答案
这可以通过提交"类型的输入元素来完成.这将对用户显示为一个按钮,单击该按钮将发送表单.
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屋!