简体   繁体   English

通过href发送POST数据

[英]Sending POST data via href

Is there any way of sending post data via an anchor tag?? 有什么方法可以通过定位标记发送帖子数据? for GET data you just have to write it directly in the URL but can we still do it for POST? 对于GET数据,您只需要直接在URL中写入即可,但是我们仍然可以将其用于POST吗? i need the link to be without any parameters and pass name=john via POST. 我需要链接没有任何参数,并通过POST传递name = john。 can this be done? 可以做到吗?

Not with plain HTML. 不能使用纯HTML。

You could use JavaScript to cancel the default behaviour of the link and submit a form (creating the form if needed). 您可以使用JavaScript取消链接的默认行为并提交表单(如果需要,可以创建表单)。

jQuery('a').on('click', function (evt) {
    jQuery('form').submit();
    evt.preventDefault();
});

… but you shouldn't do that because links and submit buttons have different affordances and you'd be sending misleading messages to the user while adding an unnecessary dependancy on JavaScript. …但是您不应该这样做,因为链接和提交按钮具有不同的承受能力,并且您会向用户发送误导性消息,同时增加了对JavaScript的不必要依赖。

If you want to make a POST request, then do it for the right reasons and do it with a form and a submit button. 如果您要发出POST请求,请出于正确的原因进行处理,并使用表单和提交按钮进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM