gpt4 book ai didi

javascript循环自动提交结果

转载 作者:行者123 更新时间:2023-11-30 11:06:07 25 4
gpt4 key购买 nike

一个 php 页面(我们称它为 page_one)检查数据库中的某些值并根据这些值在屏幕上回显不同的问题。用户设置一些 radio 并单击提交。该代码将 radio 值发送到另一个 php 文件(我们称之为 page_two),它们被写入数据库,然后代码将新值放入隐藏表单的隐藏字段中,并再次提交它们加载 page_one,其中提出了新问题。以此类推,直到出题数量结束。

为了自动提交到 page_one,我在 php 文件 page_two 中使用了以下 javascript。

<script>
var auto_refresh = setInterval(function() { submitform(); }, 50);

function submitform()
{
/*alert('test');*/
document.getElementById("hidden-form").submit();
}
</script>

在 Firefox (Mac) 和 Safari (Mac) 以及 iOS(Safari) 上一切正常:page_two 将值写入数据库并回调 page_one。

Chrome 没有执行相同的操作,而是进入一个循环,并继续每 50 毫秒调用一次 page_two,持续数千次,直到某些东西打破了这一切。

有什么帮助吗?

最佳答案

这就是 setInterval 的用途...它将每 50 mili 秒运行一次并提交表单..如果您需要它调用一次然后使用 setTimeout .

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds). The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.

引用:setInterval

The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

引用:setTimeout

关于javascript循环自动提交结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55548039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com