Using the POST Method with HTML Anchor Tags

杀马特。学长 韩版系。学妹 提交于 2019-12-02 19:03:24

You could do something like this:

<form id="myform" method="post" action="target.html">
  <input type="hidden" name="name" value="value" /> 
  <a onclick="document.getElementById('myform').submit();">click here</a>
</form>

This behaviour is specific to display tag library. It allows for easily bookmarkable search results. If you really intend to change this to make use of POST, then you'd need to rewrite the display tag library or bring in some jQuery to manipulate the links.

The remnant of your questions boils nowhere. If you want GET (idempotent requests, bookmarkable URLs, searchbot-crawable URLs, etc), then use GET. If you want POST (non-idempotent requests, non-bookmarkable URLs, non-crawlable URLs, etc), then use POST.

Usually, POST is mandatory when the request can modify the data in the server. Think of a SQL INSERT, UPDATE, DELETE, etc. You certainly won't make this kind of requests GET. Imagine that you've a table with all "delete row" links which do GET and then a searchbot comes along...

You can use javascript. On onclick of link do form.submit

The only way I know of to deal with lenghty URL is to instead use POST.

You may create a temporary form and submit it while onclick event of <a> tag.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!