I
I
impressive172020-05-01 16:58:03
JavaScript
impressive17, 2020-05-01 16:58:03

How to send a POST request to a link?

I need that when I click on a link, I send a post request to a specific address. But not with ajax. For the page to reload

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Polos, 2020-05-01
@dimovich85

Instead of a link, you make a form, a POST method, and a submit button.

R
Roman Sarvarov, 2020-05-01
@megakor

Or, as Dmitry said (we make a form and insert a button).
Or with jQuery.

<form action="/" class="test__form" method="POST">
    <a href="#" class="submitlink">click me</a>
</form>

let form = $('.test__form'),
    submitLink = form.children('.submitlink');

submitLink.click(function(e) {
    e.preventDefault();
    form.submit();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question