简体   繁体   中英

a href tag to place a link

I have to place a link to a webpage through an <a> .The webpage link contains some request parameters and I don't want to send it across through the browser directly (meaning I want to use something similar to POST method of FORM).

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

I am using this inside a jsp page and is there a way to post it through javascript or any other way where I don't pass the request parameters through the url?

You can use links to submit hidden forms, if that's what you're asking.

<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>

Use the form tag with hidden fields to submit 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>

You can use AJAX for that. For example, with jQuery , you can use the 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});
  });
});

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