简体   繁体   English

如何在提交时重新加载页面

[英]How to reload a page on Submit

I have a Bootstrap Modal which contains a form.我有一个包含表单的 Bootstrap Modal。 The Modal also contains a Submit and Cancel Button.模态还包含提交和取消按钮。 The cancel button is working fine and it is closing the Modal successfully.取消按钮工作正常,并且成功关闭了 Modal。 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.现在,根据我对模态的提交按钮单击的要求,通过将用户输入传递给 Web 服务,表单正在成功提交,但模态没有关闭。 Also I need to reload the page on Submit button click event only.此外,我只需要在提交按钮单击事件上重新加载页面。 Here is my HTML..这是我的 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 ..我尝试了以下方法来关闭 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.根据我的要求,我需要在提交事件时关闭模态并在从 Web 服务返回后重新加载页面。 How can I do this with Jquery?我怎样才能用 Jquery 做到这一点?

Note: I am not supposed to use Ajax Call here ..I need to submit form from form action only注意:我不应该在这里使用 Ajax Call ..我只需要从表单操作提交表单

This HTML will not work:此 HTML 将不起作用:

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

But this HTML does the job:但是这个 HTML 可以完成这项工作:

<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:如果您希望在提交表单时重新加载页面,请使用onsubmit事件处理程序:

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

This code should reload the page, submit your form, and close the modal.此代码应重新加载页面,提交表单并关闭模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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