Search code examples
javascriptjqueryajaxajaxform

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.

$(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.

I am getting the value as listBean.Item.getInitialWeight().

what am i doing wrong ?

Any suggestions are welcome.Thanks for your time ..


Solution

  • data: $('#form').serialize(),
    

    should become

    data: $('form').serialize(),
    

    You are referencing to the wrong DOM item