简体   繁体   中英

Page Reload Delay after submit JSP

I've been trying to delay page reload after submit, using the script below but i can't make it to work. I'm wondering if someone can help me. Thanks.

Button

<input type="submit" id="success" class="btn btn-primary" data-toggle="modal" data-target="#modal-1" value ="Save"  onclick="refresh(10000)" value="Call function"/>

Java Script

<script type="text/javascript">
function refresh (timeoutPeriod){ 
    refresh = setTimeout(function(){window.location.reload(true);},timeoutPeriod); 
} 

using jQuery it should be something like that:

$('#yourformid').submit(function(e){
  e.preventDefault();
  setTimeout(function(){window.location.reload(true);},timeoutPeriod);
});

it means, you should catch form submit event, then prevent default action, and reload the page after timeout expires.

EDIT:

in case you need to submit the form with a delay, not just reload it:

var readyToSubmit = false;
$('#yourformid').submit(function(e){
  var $self = $(this);
  if (!readyToSubmit) {
    setTimeout(function(){
       readyToSubmit = true;
       $self.submit();
    },2000);
    return false;
  }
  return true;
});

fiddle: http://jsfiddle.net/vtn2wLnv/

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