如何在URL中传递POST参数? [英] How can I pass POST parameters in a URL?
问题描述
基本上,我认为我做不到,但是很高兴能被证明是错误的.
Basically, I think that I can't, but I would be very happy to be proven wrong.
我正在用PHP动态生成HTML菜单,为每个当前用户添加了一个菜单项,因此我得到了类似< a href =" process_user.php?user =< user>>
,但相对于GET,我更喜欢POST.
I am generating an HTML menu dynamically in PHP, adding one item for each current user, so that I get something like <a href="process_user.php?user=<user>>
, but I have a preference for POST over GET.
是否有一种方法可以将信息作为POST参数传递,而不是通过可点击的HREF链接进行GET?
Is there a way to pass the information as a POST parameter, rather than GET from a clickable HREF link?
不允许使用JavaScript.
I am not allowed to use JavaScript.
抢劫犯了与;您可以使用按钮代替锚点,而只是将按钮样式设置为看起来像链接.这样,您可以将值保存在同一表单内的隐藏字段中,以通过POST发送.
It looks like Rob is on to something with "You could use a button instead of an anchor and just style the button to look like a link. That way you could have your values in hidden fields inside the same form to be sent via POST"
推荐答案
您可以使用样式为链接的表单.不需要JavaScript:
You could use a form styled as a link. No JavaScript is required:
<form action="/do/stuff.php" method="post">
<input type="hidden" name="user_id" value="123" />
<button>Go to user 123</button>
</form>
CSS:
button {
border: 0;
padding: 0;
display: inline;
background: none;
text-decoration: underline;
color: blue;
}
button:hover {
cursor: pointer;
}
请参阅: http://jsfiddle.net/SkQRN/
这篇关于如何在URL中传递POST参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!