簡體   English   中英

如何在提交時重新加載頁面

[英]How to reload a page on Submit

我有一個包含表單的 Bootstrap Modal。 模態還包含提交和取消按鈕。 取消按鈕工作正常,並且成功關閉了 Modal。 現在,根據我對模態的提交按鈕單擊的要求,通過將用戶輸入傳遞給 Web 服務,表單正在成功提交,但模態沒有關閉。 此外,我只需要在提交按鈕單擊事件上重新加載頁面。 這是我的 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>

我嘗試了以下方法來關閉 Modal ..

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

根據我的要求,我需要在提交事件時關閉模態並在從 Web 服務返回后重新加載頁面。 我怎樣才能用 Jquery 做到這一點?

注意:我不應該在這里使用 Ajax Call ..我只需要從表單操作提交表單

此 HTML 將不起作用:

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

但是這個 HTML 可以完成這項工作:

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

所以瀏覽器有足夠的時間提交表單然后重新加載頁面;-)

提交表單后,您可以通過 javascript 進行此調用:

window.location.reload();

如果您希望在提交表單時重新加載頁面,請使用onsubmit事件處理程序:

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

此代碼應重新加載頁面,提交表單並關閉模式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM