我是 js 和 ajax 的新手。我想要一个调用disp.php
文件并在load.php
. ajax 代码应该从load.php
to传递一个值,disp.php
并且每次调用之间必须有 5 秒的延迟。
基本上我想替换以下由于脚本超时而失败的 php 代码。load()
并且disp()
是函数disp.php
require("disp.php");
for($i = 1; $i <= $pt[1]; $i++)
{
load($mat,$i);
disp();
sleep(5);
}
要从 Javascript 进行 Ajax 调用,请参阅如何在没有 jQuery 的情况下进行 AJAX 调用?
并在每五秒后使用 setTimeout 拨打电话
<script>
function callLoad() {
......write logic to call the PHP file here...
}
var callCount = 0;
function callLoop() {
callLoad();
callCount ++;
if(callCount == 5) return; // Stop the loop
setTimeout(function() {
callLoop();
}, 5000); // Wait for 5 second to make the call again
}
window.onload = callLoop; // Start the loop after the page has finished loading
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句