开发者

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 thro开发者_运维技巧ugh 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});
  });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜