Skip to content

Instantly share code, notes, and snippets.

@ayuLiao
Last active June 25, 2018 08:19
Show Gist options
  • Save ayuLiao/70e98474081d6cb6f1885bcc84385b39 to your computer and use it in GitHub Desktop.
Save ayuLiao/70e98474081d6cb6f1885bcc84385b39 to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment