PHP и JavaScript работают взаимозависимо, но не вместе - PullRequest
0 голосов
/ 03 марта 2012

У меня есть JavaScript WebApp, который запускает экран киоска. Каждые 1 час он вызывает страницу PHP на удаленном сервере для обновления информации в приложении. Это прекрасно работает, когда я делаю это с обновлением о погоде, хотя когда я использую его для отправки отчета, происходит сбой.

Если я просто использую тот же URL в веб-браузере, он добавит запись в текстовый файл, но когда Java Script вызывает его, он не работает. Примечание: я знаю, что время таймера очень мало, это было только для целей тестирования ...]

ПРИМЕЧАНИЕ Я попытался добавить PHP правильно, в редакторе все нормально, когда я сохраняю его, он не отображается правильно, извините, пожалуйста, дайте мне знать, если вам нужен остальной PHP код и я буду PM

Код киоска JavaScript:

    {
    var t=setTimeout("updateLogReport()",3000);
    }

        function updateLogReport()
            {   
            // New reporting system
            // This simply sends information to a remote php page which deals with the given data
            var response = null; 
            var connection = new ActiveXObject("Microsoft.XMLHTTP"); 
            try 
            { 
                connection.open("GET", "http://www.EXAMPLE.com/EXAMPLE/reporting/remote_reporting_answer.php?type=Java_Checkin&reportingDisplayPricesDynamic=yes&machine=Display", false); 
                connection.send(); 
                if(connection.readyState == 4) response = connection.responseText; 
            }        
            catch(e) 
            { 
                // Alerts disabled for real time deployement
                alert("ERROR (reporting): The remote host could not be found or the connection was refused."); 
                return false; 
            } 
            alert(response);

                // Recall the timer
                timerLogReport()
        }

Появится «Alert», и у него будет ответ, который вы увидите ниже в конце скрипта PHP, однако он отказывается добавлять текст в текстовый файл, несмотря на то, что я должен был набрать

http://www.EXAMPLE.com/EXAMPLE/reporting/remote_reporting_answer.php?type=Java_Checkin&reportingDisplayPricesDynamic=yes&machine=Display

Прямо в браузер он добавит текст в файл

Код PHP:

<?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;
        ?>
...