[英]Jquery serialize does not send input fields
I have a form with input fields which will be triggered every 1 min to update the user entries to the server. 我有一个带有输入字段的表单,它将每1分钟触发一次,以将用户条目更新到服务器。
$(document).ready(function()
{
timer = setInterval(function() { save(); }, 60000);
});
function save() {
jQuery('form').each(function() {
jQuery.ajax({
url: "http://localhost:7002/submitStudent.do?requestType=auto&autosave=true",
data: $('#form').serialize(),
type: 'POST',
success: function(data){
if(data && data == 'success') {
alert("data saved");
}else{
}
}
});
});
}
And here is my form 这是我的表格
<form name="listBean">
<c:forEach var="Item" items="${listBean.nameList}" varStatus="status">
<input type="number"name="nameList<c:outvalue='[${status.index}]'/>.initialWeight" onchange="checkOnChange(this,'<c:out value='${Item.personId}'/>','<c:out value='${Item.minWeight}'/>','<c:out value='${Item.maxWeight}'/>','<c:out value='[${status.index}]'/>')">
<br><br>
<input type="number" name="nameList<c:out value='[${status.index}]'/>.finalWeight" onchange="checkOnChange(this,'<c:out value='${Item.personId}'/>','<c:out value='${Item.minWeight}'/>','<c:out value='${Item.maxWeight}'/>','<c:out value='[${status.index}]'/>')">
<br><br>
<input type="text" class="formtext" name="nameList<c:out value='[${status.index}]'/>.Reason" id ="reason<c:out value='[${status.index}]'/>" value="" maxlength="255" >
<br><br>
<input type="submit" value="submit" id="submit" />
</c:forEach>
</form>
So the ajax calls to the server works fine for every 1 min .But the values entered are not available at the server side. 因此,每隔1分钟对服务器的ajax调用就可以正常工作。但是输入的值在服务器端不可用。
I am getting the value as listBean.Item.getInitialWeight(). 我得到的值是listBean.Item.getInitialWeight()。
what am i doing wrong ? 我究竟做错了什么 ?
Any suggestions are welcome.Thanks for your time .. 欢迎任何建议。感谢您的时间..
data: $('#form').serialize(),
should become 应该成为
data: $('form').serialize(),
You are referencing to the wrong DOM item 您所指的是错误的DOM项目
jQuery will treat your jQuery将对待您
$('#form')
as "an element with id form". 作为“具有ID形式的元素”。 So you should change your jQuery DOM reference.
因此,您应该更改jQuery DOM参考。
In your case it can be 在你的情况下可以
$('form[name="listBean"]').serialize()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.