0

我知道类似的问题被多次提出,正如我在搜索中看到的那样。但是我无法在 PHP 中为我正在使用的列表管理刷新工作。

刷新日期时间是一个简单的测试,它有效。切换到复杂功能时,它不会。这让我很困惑。希望你能告诉我我做错了什么。

目前我正在准备一个加载 X 数量的位置及其预订的页面。每秒钟我都希望刷新位置及其总数。

目前我的代码:

DIV,包含启动 MySQL 查询的 PHP 函数,以 HTML 格式/布局列出数据:

echo '  <div id="location">
            <div id="session">
            '.listLocationToBook($current_user_id, $filter_city, $date, $token, $url).'
            </div>
        </div>';

脚本

<script type="text/javascript">
    setInterval("my_function();",3000); 
    function my_function(){
      $('#location').load(location.href + ' #session');
    }
</script>

当我在 div 中放置一个计时器(日期时间)而不是 PHP 函数时,我看到时间随着 3 秒的增加而增加。

任何原因这不适用于 PHP 函数?我该如何解决/努力寻找替代方案?

提前致谢

4

1 回答 1

0

the function is working and has an output without adding it into javascript. I found the solution in the following: the php function did the echo on the html snippet. Instead of echo I put this into an a variable and returned this variable. Without the return, the content was not showing in Javascript. Another thing I learned, maybe useful for someone else

于 2020-06-14T13:21:21.510 回答