Answer the question
In order to leave comments, you need to log in
How to make a POST request on link click?
How to make a POST request on link click? On clicking the link, you need to send a post request to a specific URL. back-end on GOLANG
Answer the question
In order to leave comments, you need to log in
The link is in the browser. Means it is necessary to do means of the browser.
In pure javascript on the click of a button
<a href="javascript:void(0)" click="sendPost()">Linkk</a>
<script>
function sendPost() {
var xhr = new XMLHttpRequest();
var body = 'name=' + encodeURIComponent(name) +
'&surname=' + encodeURIComponent(surname);
xhr.open("POST", '/submit', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(body);
}
</script>
<form href="/my/url" type="post" id="myForm">
<input type="hidden" name=name" value="Sergey" />
</form>
<a href="javascript:void(0)" click="document.getElementById('myForm').submit()">Linkk</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question