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

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

本文介绍了如何在提交时重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含表格的Bootstrap Modal.该模态还包含一个提交"和取消"按钮.取消按钮工作正常,并且已成功关闭模态.现在,按照我对模式的提交按钮"的要求,通过将用户输入传递到Web服务,表单已成功提交,但模式没有关闭.另外,我只需要在提交"按钮单击事件上重新加载页面.这是我的HTML.

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

根据我的要求,我需要关闭提交时出现的模态"事件,并在从Web Service返回后重新加载页面.如何使用Jquery做到这一点?

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?

注意:我不应该在这里使用Ajax Call ..我只需要通过表单操作提交表单

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

推荐答案

此HTML无效:

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

但是此HTML可以完成这项工作:

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

这篇关于如何在提交时重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:04