通过jQuert Ajax的POST请求将表单序列化,然后提交到后台时,所有数据都为空的是怎么回事?
这是大致的代码
<html>
<head>
....
</head>
<body>
<div>
<form id="nq_data">
<div class="col-md-6 form-group">
<label for="name">编号</label>
<input type="text" class="form-control" id="openbeds_numbers"
placeholder="0">
</div>
<div class="col-md-6 form-group">
<label for="name">数目</label>
<input type="text" class="form-control" id="pnurse_begin_totalnumbers"
placeholder="0">
</div>
</form>
</div>
<div class="col-md-12 form-group">
<button style="width: 150px" type="button" class="btn btn-default"
onclick="savaData()">暂存</button>
</div>
<script type="text/javascript">
function savaData() {
$.post("<%=basePath%>savaData.action",
$("nq_data").serialize(),function(data){
if(data == "OK"){
alert("已成功保存!");
window.location.reload();
}else{
alert("保存失败!");
window.location.reload();
}
});
}
</script>
</body>