Href tag for link placement

I need to put a link to a webpage through <a>. The link to the web page contains some request parameters, and I do not want to send it directly through the browser (this means that I want to use something similar to the POST FORM method).

<a href="www.abc.do?a=0&b=1&c=1>abc</a>

Am I using this inside a jsp page and is there a way to publish it via javascript or any other way when I don't pass the request parameters via the url?

+3
source share
3 answers

You can use links to submit hidden forms if that is what you are asking for.

<a href="#" onclick="submitForm('secretData')">Click Me</a>

<form id="secretData" method="post" action="foo.php" style="display:none">
  <input type="hidden" name="foo" value="bar" />
</form>

<script type="text/javascript">
  function submitForm(formID) {
    document.getElementById(formID).submit();
  }
</script>
+5
source

Use the tag formwith hidden fields to send your data:

 <a href="#" onclick="document.frm.submit(); return false">GO !!</a>

 <form name="frm" action="www.abc.do" method="post">
   <input type="hidden" value="your-data" name="whatever">
   <input type="hidden" value="your-data" name="whatever">
   <input type="hidden" value="your-data" name="whatever">
 </form>
+1

You can use AJAX for this. For example, jQuery you can use the post post function :

<a href="#" id="myMagicLink">clickMe</a>

<script type="text/javascript">
$(function(){
  $("#myMagicLink").click(function(){
    $.post("www.abc.do", {"a":0, "b":1, "c":1});
  });
});
0
source

Source: https://habr.com/ru/post/1732472/


All Articles