ayuLiao
4/25/2018 - 2:32 AM

ajax post提交

AJAX代码片段,按钮点击事件触发AJAX,通过POST方式将input中的内容发送给后端

<from>
  <div class="form-group">
      <label >工会ID</label>
      <input class="form-control" id="parentId">
    </div>
    <div class="form-group">
      <label >用户ID</label>
      <input class="form-control" id="userId" >
    </div>
  <button  type="submit" class="btn btn-default">提交</button>
</from>
<script type="text/javascript">

  $("button").click(function(){
    var parentId = $("#parentId").val();
    var userId = $("#userId").val();

    $.post("后端url地址",
          {
            parentId:parentId,
            userId:userId,

          },
          function(data,status){
            if(status=="success" && data.status==1){
                alert(data.msg);
            }
            if(data.status==0){
                alert(data.msg);
            }
          }
         );
      });
</script>