我有一个运行Kiosk屏幕的JavaScript WebApp。它每1小时调用一个远程服务器上的PHP页面来更新应用程序上的信息。当我使用天气更新时,这非常有效,但是当我用它来发送报告失败时。
如果我只是在Web浏览器中使用相同的URL,那么它将向文本文件中添加一条记录,但是当Java Script调用它时,它不起作用。注意:我知道定时器时间非常短,这仅用于测试目的......]
注意我已经尝试正确添加PHP,在编辑器中保存它没关系它没有正确显示,对不起,请告诉我你是否需要其余的PHP代码和我将PM
JavaScript Kiosk代码:
{
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()
}
将显示“警报”,它将在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;
?>