How to reload a page on Submit

44,920

Solution 1

This HTML will not work:

<form onsubmit="window.location.reload();">

But this HTML does the job:

<form onsubmit="setTimeout(function(){window.location.reload();},10);">

So the browser has enough time to submit the form and then reload the page ;-)

Solution 2

after submitting your form you can just make this call via javascript:

window.location.reload();
Share:
44,920
Lara
Author by

Lara

Updated on March 27, 2020

Comments

  • Lara
    Lara over 4 years

    I have a Bootstrap Modal which contains a form. The Modal also contains a Submit and Cancel Button. The cancel button is working fine and it is closing the Modal successfully. Now as per my requirement on Submit Button Click of the Modal the Form is Submitting Successfully by passing the User inputs to Web Service but Modal is not getting closed. Also I need to reload the page on Submit button click event only. Here is my HTML..

    <div class="modal fade" id="StudentModal" tabindex="-1" role="dialog" aria-labelledby="StudentModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
      <div class="modal-content">
         <form action="~/GetStudent" class="form-horizontal" role="form" method="post" id="frmStudent">
            <div class="modal-footer">
               <div class="pull-right">
                  <button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-ok"></i> Save</button>
                  <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>
               </div>
            </div>
         </form>
      </div>
    

    I tried following ways to close the Modal ..

    $('#frmStudent').submit(function() {
    $('#StudentModal').modal('hide');
    return false;
    });
    

    As per my Requirement I need to close the Modal on Submit event and reload the page after getting back from Web Service. How can I do this with Jquery?

    Note: I am not supposed to use Ajax Call here ..I need to submit form from form action only