【发布时间】:2017-09-12 11:55:07
【问题描述】:
不太了解 AJAX。这就是问题所在。
我正在读取填充一些全局变量的 PHP 函数中的数据库,我可以访问这些变量,但我需要定期调用 php 函数。
<?php
function thatIwant()
{
//read database
return 10;
}
echo("
<script>
function refreshDiv()
{
//// this is where I need to call the above function.
var refresher = setTimeout('refreshDiv()', 2000);
}
</script>
");
?>
【问题讨论】:
-
您必须使用 AJAX。客户端代码只能通过 HTTP 请求调用服务器端代码。
-
“不太了解 AJAX。” That is fairly easily remedied.
-
另外,使用字符串参数调用
setTimeout是不好的做法。使用函数引用:var refresher = setTimout(refreshDiv, 2000);
标签: javascript php html