javascript - Reload a page after jquery ajax call -


i have jsp page displays details of student .based on student selection dropdown box on change event fired , retrieve min , max marks student.

<form name="listbean">      <c:foreach var="item" items="${listbean.namelist}" varstatus="status">         <input type="number"name="namelist<c:outvalue='[${status.index}]'/>.initialmarks"/>          <input type="number" name="namelist<c:out value='[${status.index}]'/>.finalmarks"/>          <input type="submit" value="submit" id="submit" />         minmarks:<c:out value="${item.minmarks}"/></c:if>          maxmarks:<c:out value="${item.maxmarks}"/></c:if>      </c:foreach> </form> 

after retrieval ,updated data stored bean.server request handled using jquery.ajax() method

function onchange() {     jquery('form').each(function() {         jquery.ajax({             url: "http://localhost:9001/submitstudent.do?requesttype=auto",             data: $('form').serialize(),             type: 'post'           });            location.reload();     });  } 

once server response successful , reloading page page refreshed bean data set during ajax call.

but not displaying data?what doing wrong ?

or there better solution achieve this?

any suggestions welcome .

thanks

it looks reloading page after sending ajax request, potentially before server has received , processed it.

you store ajax requests in array , reload page when requests have completed using jquery's when().

function onchange() {     var requests = [];      jquery('form').each(function() {         requests.push(jquery.ajax({             url: "http://localhost:9001/submitstudent.do?requesttype=auto",             data: $('form').serialize(),             type: 'post'         }));     });      jquery.when.apply(jquery, requests).then(location.reload, errhandler); }  function errhandler (err) {     // handle errors } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -