user2707590
user2707590

Reputation: 1126

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?

Upvotes: 0

Views: 4142

Answers (1)

Quentin
Quentin

Reputation: 943207

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.

Upvotes: 6

Related Questions