开发者

Make submit of form slower

开发者 https://www.devze.com 2023-03-29 01:50 出处:网络
Is it possible using jquery to make a form submit slower? 开发者_JAVA百科So for example when a user does a search it will do the loading 2-3 seconds longer for the postback?Not sure why you would nee

Is it possible using jquery to make a form submit slower?

开发者_JAVA百科So for example when a user does a search it will do the loading 2-3 seconds longer for the postback?


Not sure why you would need to do this, but you could do something like this:

var submitted = false;
$("form").bind('submit', function(){
    if(!submitted){
        submitted = true;
        setTimeout(function(){ $("form").trigger('submit');}, 3000);
        return false;
    }else{
        return true;
    }
});


var t = setTimeout("javascript statement",milliseconds);

That might be what you need.


If you're making a server side request, you could always just delay the response. In PHP this could be done with sleep.

sleep(3);


setTimeout(function(){
    yourFormSubmitionAfter2Seconds();
}, 2000);

or in PHP

sleep(2);


Why not use a click method that does something (e.g. a delay) and than triggers the post if it's ready? Like so:

$('#mybutton').click(function(){
  //wait, demonstrate, whatever
  //post my form
});


I'm not sure why you'd want this but you can possibly make your form submit programmatically and have.

$`('#form').delay(2000).submit();

`

0

精彩评论

暂无评论...
验证码 换一张
取 消