Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 512
Lara Avatar asked Nov 02 '15 18:11

Lara


People also ask

Do not refresh page after form submit?

Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.

How do you reload a form in HTML?

Window location.reload() The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.

How do you refresh a page in JavaScript?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.


2 Answers

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

like image 177
adilbo Avatar answered Oct 07 '22 15:10

adilbo


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

window.location.reload();
like image 21
Ayo K Avatar answered Oct 07 '22 13:10

Ayo K