如何在URL中传递POST参数? [英] How to pass POST parameters in a URL?

查看:3513
本文介绍了如何在URL中传递POST参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我认为我不能,但很高兴被证明是错误的。

Basically, I think that I can't, but 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链接传递?

Is there any way to pass the info as a POST parameter, rather than GET from a clickable HREF link?

更新:对不起,我不允许使用JS - 我应该说,我的不好

Update: sorry, I am not allowed to use JS - I shoulda said, my bad

更新到更新:看起来@Rob正在使用你可以使用按钮代替锚点,只需将按钮设置为看起来像链接。这样你就可以通过POST发送同一表格内的隐藏字段中的值

Update to the update: it looks like @Rob is on to somethign 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 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屋!

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