
html post请求之a标签的两种用法解析
这篇文章主要介绍了 html post请求之a标签的两种用法, 本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧。
tml post请求之a标签的两种用法举例,具体内容如下:
1、使用ajax来发起POST请求
HTML代码如下:
1 | <a href="https://www.jb51.net/" class="a_post">发起POST请求</a> |
JQuery代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $(".a_post").on("click",function(event){ event.preventDefault();//使a自带的方法失效,即无法调整到href中的URL(https://www.cnblogs.com/) $.ajax({ type: "POST", url: "url地址", contentType:"application/json", data: JSON.stringify({param1:param1,param2:param2}),//参数列表 dataType:"json", success: function(result){ //请求正确之后的操作 }, error: function(result){ //请求失败之后的操作 } }); }); |
2、使用form表单来发起POST请求
1 2 3 4 | <form id="_form" method="post" action="target"> <input type="hidden" name="name" value="value" /> <a onclick="document.getElementById('_form').submit();">点击提交</a> </form> |
总结
到此这篇关于html post请求之a标签的两种用法解析的文章就介绍到这了,更多相关html post请求 a标签内容请搜索好哇网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持好哇网!