通过定位标记发送$ _POST数据 [英] send $_POST data via anchor tag
问题描述
是否可以通过<a>
标签以某种方式发送$_POST[]
数据?因为它似乎在页面加载后自动执行$_POST[]
,而不是在我按下Anchor标签时执行.
is it possible to somehow send $_POST[]
data via a <a>
tag? because it seems to automaticly execute the $_POST[]
once the page loads rather than when I press the Anchor tag.
修改: 所以我想要达到的目标是这样的:
edit: so what I'm trying to achieve is something like this:
我想要一个锚标签,该标签通常会转到somepage.php?variable=something
但是我不想使用$_GET[]
而是通过$_POST
I want an anchor tag which would normaly go to somepage.php?variable=something
but instead of using $_GET[]
I want to send the variable via $_POST
推荐答案
您可以使用jQuery和HTML表单实现
You can achieve this using jQuery and a HTML form
HTML:
<form method="post" name="redirect" class="redirect">
<input type="hidden" class="post" name="post" value="">
<input type="submit" style="display: none;">
</form>
按钮:(html)
<a href='javascript:void(0)' class='button' var='DATAHERE'>sometexthere</a>
JavaScript,或更确切地说是jQuery:
Javascript, or rather said jQuery:
$(".button").click(function() {
var link = $(this).attr('var');
$('.post').attr("value",link);
$('.redirect').submit();
});
此jQuery代码侦听对附加有类button
的商品的任何点击,
并读出它们的"var"值,基本上,只要他们附加了button
类,就可以使用此方法使用任何类型的HTML元素.
this jQuery code listen's to any clicks on the items with the class button
attached to them,
and reads out their "var" value, basicly you could use any kind of HTML element using this method as long as they have the button
class attached to it.
这篇关于通过定位标记发送$ _POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!