PHP和JavaScript相互依赖,但不能一起工作

PHP和JavaScript相互依赖,但不能一起工作,php,javascript,kiosk,Php,Javascript,Kiosk,我有一个JavaScript网络应用程序,它运行一个信息亭屏幕。它每1小时调用一个远程服务器上的PHP页面来更新应用程序上的信息。当我使用天气更新时,它工作得非常好,尽管当我使用它发送报告时失败了 如果我只是在web浏览器中使用相同的URL,那么它将向文本文件中添加一条记录,但是当Java脚本调用它时,它不起作用。注意:我知道计时器时间很短,这只是出于测试目的…] 注:我已经尝试正确添加PHP,在编辑器中保存时没有问题,它没有正确显示,对此表示抱歉,如果您需要剩余的PHP代码,请告诉我,我将进行

我有一个JavaScript网络应用程序,它运行一个信息亭屏幕。它每1小时调用一个远程服务器上的PHP页面来更新应用程序上的信息。当我使用天气更新时,它工作得非常好,尽管当我使用它发送报告时失败了

如果我只是在web浏览器中使用相同的URL,那么它将向文本文件中添加一条记录,但是当Java脚本调用它时,它不起作用。注意:我知道计时器时间很短,这只是出于测试目的…]

注:我已经尝试正确添加PHP,在编辑器中保存时没有问题,它没有正确显示,对此表示抱歉,如果您需要剩余的PHP代码,请告诉我,我将进行PM

JavaScript信息亭代码:

警报将显示,它将有响应,您将在下面的PHP脚本末尾看到,但是它拒绝将文本添加到文本文件中,不管我是否要键入

http://www.EXAMPLE.com/EXAMPLE/reporting/remote_reporting_answer.php?type=Java_Checkin&reportingDisplayPricesDynamic=yes&machine=Display
直接进入浏览器,它会将文本添加到文件中

PHP代码:


切勿将字符串传递给setInterval或setTimeout。这样做和使用eval一样糟糕,而且一旦使用变量,就会导致代码无法读取,甚至可能不安全,因为您需要将变量插入字符串中,而不是传递实际变量。正确的解决方案是setIntervalfunction{/*您的代码*},msecs;。这同样适用于setTimeout。如果只想调用一个没有任何参数的函数,也可以直接传递函数名:setIntervalsomeFunction,毫秒;请注意,函数名后面没有为什么不使用任何Java脚本框架等jQuery、Mootools。。。然后使用Ajax方法在服务器和客户端之间发送和接收数据。
http://www.EXAMPLE.com/EXAMPLE/reporting/remote_reporting_answer.php?type=Java_Checkin&reportingDisplayPricesDynamic=yes&machine=Display
<?php
// Receives information sent from 

// This information can be used to help problem solve and
// indentify run times etc

            // File to save to
             $file = 'reports.html';

            // Calculate the date
             $time = date('d-m-Y h:m:s');

             // Get variables sent from the machine
             $machine = $_GET['machine'];
             $type = $_GET['type'];
             $reportingDisplayPricesDynamic = $_GET['reportingDisplayPricesDynamic'];
             $softwareVersion = $_GET['softwareVersion'];

             // Set the color of the text
             if($type=="Startup") {
                 $fontColor = "#33c1bc";
             }

             else if($type=="Checkin") {
                 $fontColor = "#52b131";                 
             }

             else if($type=="Java_Checkin") {
                 $fontColor = "#ffcc00";                 
             }

             else {
                 // For everything else set to red
                 $fontColor = "#ee2617";
             }

             // Text to add to file
                $error = "
                    <p>
                    <div id='report' style='display:block; width:100%; height:40px;'>
                      <div id='date' style='height:40px; width:150px; float:left; display:inline; padding:5px; background-color:#c0c0c0;'>                  
                      Machine name
                      <br>
                      $machine
                      </div>

                      <div id='date' style='height:40px; width:150px; float:left; display:inline; padding:5px; border-left:1px solid #c0c0c0;'>                 
                      Date
                      <br>
                      <b>$time</b>
                      </div>

                      <div id='type' style='height:40px; width:150px; float:left; display:inline; padding:5px; color:$fontColor; border-left:1px solid #c0c0c0;'>               
                      Type
                      <br>
                      <b>$type</b>
                      </div>

                      <div id='ScreenState' style='height:40px; width:150px; float:left; display:inline; padding:5px; border-left:1px solid #c0c0c0;'>                  
                      Prices Screen
                      <br>
                      <b>$reportingDisplayPricesDynamic</b>
                      </div>

                      <div id='ScreenState' style='height:40px; width:150px; float:left; display:inline; padding:5px; color:#808080; border-left:1px solid #c0c0c0;'>               
                      Software version
                      <br>
                      <b>$softwareVersion</b>
                      </div>
                    </div>
                    <br></p>
                ";

             // Write the contents to the file, 
             // using the FILE_APPEND flag to append the content to the end of the file
             // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
             file_put_contents($file, $error, FILE_APPEND | LOCK_EX);

             // Echo a success message, this will be displayed in the application
             echo "Time stamp :: " . $time;
        ?>