开发者

How do I use javascript to repeatedly submit a form?

开发者 https://www.devze.com 2023-02-13 09:39 出处:网络
How can I submit a form开发者_如何学JAVA every 5 seconds using javascript?setTimeout(\"$(\'#form\').submit()\",5000);

How can I submit a form开发者_如何学JAVA every 5 seconds using javascript?


setTimeout("$('#form').submit()",5000);

without jQuery...

setTimeout("document.forms['yourform'].submit();",5000);


Not sure why you would want to do that, but you can use setTimeout()docs or setInterval()docs methods.

Keep in mind though that when you submit a form you submit it to a url, and you go to that url (unless you use ajax). If your target page is the same as the source page, then the page is reloaded so your script starts from scratch ..

the following code would submit the form 5 seconds after its execution
in a page that reloads it would execute again so it would effectively submit every 5 secs

setTimeout(function(){
              document.getElementById('formID').submit();
            }, 5000);


setTimeout will only fire once, setInterval will fire every x milliseconds

0

精彩评论

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