gpt4 book ai didi

javascript - setInterval() 中的 PHP file_get_contents() 不起作用

转载 作者:行者123 更新时间:2023-12-02 17:58:24 27 4
gpt4 key购买 nike

我尝试在 setInterval() 中使用 get_file_contents() 来重复更新一些显示文件内容的文本。代码如下:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<body>
<div id="theDiv"></div>
</body>
<script>
$("document").ready(function(){
setInterval(function(){
$("#theDiv").text("<?php echo file_get_contents('file.txt'); ?>");
console.log("<?php echo file_get_contents('file.txt'); ?>")
},500);
});
</script>

问题是:在我重新加载页面之前,文本似乎不会更新。

最佳答案

file_get_contents() 未设置为通过 setInerval 重新加载。您混淆了客户端 JavaScript 和服务器端 PHP。

您可能需要以下内容:

$("document").ready(function(){
setInterval(function(){
$("#theDiv").load('file.txt');
},500);
});

关于javascript - setInterval() 中的 PHP file_get_contents() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20794444/

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