开发者

Make submit of form slower

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜