0

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

0

2 Answers 2

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

should become

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

You are referencing to the wrong DOM item

Sign up to request clarification or add additional context in comments.

2 Comments

Or - more specific - add an id attribute to your form (if you have multiple forms on the page).
@RaphaelMüller Thanks for your reply. In the real scenario , it already has an id attached to the form and input fields.But I missed out on the example code.Apologies.
0

jQuery will treat your

$('#form')

as "an element with id form". So you should change your jQuery DOM reference.

In your case it can be

$('form[name="listBean"]').serialize()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.