当前位置: 移动技术网 > IT编程>网页制作>CSS > html post请求之a标签的两种用法举例

html post请求之a标签的两种用法举例

2020年05月12日  | 移动技术网IT编程  | 我要评论

妆遍天下,斑马鱼寿命,户口迁移证

html post请求之a标签的两种用法举例

1、使用ajax来发起post请求
html代码如下:

<a href="https://www.cnblogs.com/" class="a_post">发起post请求</a>

jquery代码如下:

$(".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请求
<form id="_form" method="post" action="target">
  <input type="hidden" name="name" value="value" /> 
  <a onclick="document.getelementbyid('_form').submit();">点击提交</a>
</form>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网