Php 自动更新文本文件的Ajax和setInterval()未更新

Php 自动更新文本文件的Ajax和setInterval()未更新,php,ajax,setinterval,auto-update,Php,Ajax,Setinterval,Auto Update,我有两个文本文件,它们通过ajax显示在网页上。我需要这两个文件更新,一旦更多的文本添加到文本文件。当我完成这个脚本时,我在本地主机上对它进行了测试,所有的脚本都正常工作。现在我试图让它在我的网络主机上工作,并且文本正在显示,但是当需要更新文件时,没有任何更新 我尝试禁用ajax响应的缓存,但文件仍然没有更新 代码如下: <html> <head> <script> $.ajaxSetup ({ cache: false }); function Upd

我有两个文本文件,它们通过ajax显示在网页上。我需要这两个文件更新,一旦更多的文本添加到文本文件。当我完成这个脚本时,我在本地主机上对它进行了测试,所有的脚本都正常工作。现在我试图让它在我的网络主机上工作,并且文本正在显示,但是当需要更新文件时,没有任何更新
我尝试禁用ajax响应的缓存,但文件仍然没有更新

代码如下:

<html>
<head>
<script>
$.ajaxSetup ({
cache: false
});

  function UpdateDAU()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
           document.getElementById("UpdateD").innerHTML=xmlhttp.responseText.split('\n').join('<br/>';
        }
      }
    xmlhttp.open("GET","../logs/dau.txt",true);
    xmlhttp.send();
    }

    function UpdateFireBox()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("UpdateF").innerHTML=xmlhttp.responseText.split('\n').join('<br/>');
        }
      }
    xmlhttp.open("GET","../logs/firebox.txt",true);
    xmlhttp.send();
    }


    </script>
</head>
<body>
    <script type="text/javascript">
    UpdateDAU();
    </script>
    <div id="UpdateD">No Logs</div>
    <script type="text/javascript">
    setInterval("UpdateDAU", 1000);
    </script>

    <script type="text/javascript">
    UpdateFireBox();
   </script>
<div id="UpdateF">No Logs</div>
    <script>
    setInterval("UpdateFireBox", 1000);
    </script>

</body>
</html>

$.ajaxSetup({
缓存:false
});
函数UpdateDAU()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“更新”).innerHTML=xmlhttp.responseText.split('\n').join('
'); } } open(“GET”,“./logs/dau.txt”,true); xmlhttp.send(); } 函数UpdateFireBox() { var-xmlhttp; if(window.XMLHttpRequest) { xmlhttp=新的XMLHttpRequest(); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { document.getElementById(“UpdateF”).innerHTML=xmlhttp.responseText.split('\n').join('
'); } } open(“GET”,“./logs/firebox.txt”,true); xmlhttp.send(); } UpdateDAU(); 没有日志 setInterval(“UpdateDAU”,1000); UpdateFireBox(); 没有日志 setInterval(“UpdateFireBox”,1000);



服务器上是否有需要更改的内容,或者这是我的代码的问题?
我做错了什么?

在研究了过去一周后,我终于让显示器正确更新了。 我无法从文本文件中获取要更新的文件,因此在ajax显示之前,我必须回显php文件中的文件。
这是在多台机器上工作的代码:

<html>
<head>
<script>
$.ajaxSetup ({
// Disable caching of AJAX responses */
cache: false
});

  function UpdateDAU()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("UpdateD").innerHTML=xmlhttp.responseText.split('\n').join('<br/>');
        }
      }
    xmlhttp.open("GET","getdau.php",true);
    xmlhttp.send();
    setTimeout(function() {
    UpdateDAU();       
    }, 1000)
    }

    function UpdateFireBox()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("UpdateF").innerHTML=xmlhttp.responseText.split('\n').join('<br/>');
        }
      }
    xmlhttp.open("GET","getfirebox.php",true);
    xmlhttp.send();
    setTimeout(function() {
    UpdateFireBox();       
    }, 1000)
    }


    </script>
</head>
<body>
    <script type="text/javascript">
    UpdateDAU();
</script>
<div id="UpdateD"><p class="text-warning">If there is no page...<br> Then the guards have not started there rounds.</p></div>

    <script type="text/javascript">
    UpdateFireBox();
</script>
<div id="UpdateF"><p class="text-warning">If there is no page...<br> Then the guards have not started there rounds.</p></div>

</body>
</html>

$.ajaxSetup({
//禁用AJAX响应的缓存*/
缓存:false
});
函数UpdateDAU()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“更新”).innerHTML=xmlhttp.responseText.split('\n').join('
'); } } open(“GET”,“getdau.php”,true); xmlhttp.send(); setTimeout(函数(){ UpdateDAU(); }, 1000) } 函数UpdateFireBox() { var-xmlhttp; if(window.XMLHttpRequest) { xmlhttp=新的XMLHttpRequest(); } xmlhttp.onreadystatechange=函数() { if(xmlhttp.readyState==4&&xmlhttp.status==200) { document.getElementById(“UpdateF”).innerHTML=xmlhttp.responseText.split('\n').join('
'); } } open(“GET”,“getfirebox.php”,true); xmlhttp.send(); setTimeout(函数(){ UpdateFireBox(); }, 1000) } UpdateDAU();

UpdateFireBox();

以下是用于显示文件的PHP文件:

<?php
$file = file_get_contents('../logs/dau.txt', true);
echo $file;
?>

第二个PHP文件是相同的:

<?php
$file = file_get_contents('../logs/firebox.txt', true);
echo $file;
?>

使用此代码,txt文件中的日志将每秒更新和显示,而无需刷新页面



如果有一种方法可以使用这些相同的步骤,但只使用1个php文件而不是2个,请告诉我,我将删除我的答案并选择您的答案