简体   繁体   中英

How to reload a page on Submit

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

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 ;-)

提交表单后,您可以通过 javascript 进行此调用:

window.location.reload();

If you want the page to reload when you submit a form, use the onsubmit event handler:

document.getElementById("frmStudent").onsubmit = function(){
    location.reload(true);
}

This code should reload the page, submit your form, and close the modal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM