简体   繁体   中英

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? i need the link to be without any parameters and pass name=john via POST. can this be done?

Not with plain HTML.

You could use JavaScript to cancel the default behaviour of the link and submit a form (creating the form if needed).

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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