HTML错误预期表达式,得到'<'

时间:2015-08-21 17:01:13

标签: php html json

我有一个python脚本,它将日期时间戳和温度记录到MySQL数据库中。我每小时都会使用一个cron作业来记录。我有以下PHP脚本,它从数据库中检索数据并以JSON验证格式转换它。这已被证实有效。

<?php
// Connect to MySQL
$link = mysql_connect( 'localhost', '****', '****' );
if ( !$link ) {
  die( 'Could not connect: ' . mysql_error() );
}

// Select the data base
$db = mysql_select_db( 'home_sensing', $link );
if ( !$db ) {
  die ( 'Error selecting database \'test\' : ' . mysql_error() );
}

// Fetch the data
$query = "
  SELECT *
  FROM temp";
$result = mysql_query( $query );

// All good?
if ( !$result ) {
  // Nope
  $message  = 'Invalid query: ' . mysql_error() . "\n";
  $message .= 'Whole query: ' . $query;
  die( $message );
}

// Print out rows
$prefix = '';
echo "[\n";
while ( $row = mysql_fetch_assoc( $result ) ) {
  echo $prefix . " {\n";
  echo '  "DateTime": "' . $row['datetime'] . '",' . "\n";
  echo '  "Temperature": ' . $row['temp'] . '' . "\n";
  echo " }";
  $prefix = ",<br>";
}
echo "\n]";
// Close the connection
mysql_close($link);
?>

我使用以下html在图表上显示数据

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Basement temperature monitor</title>
</head>
<body>

  <!-- prerequisites -->
  <link rel="stylesheet" href="https://www.amcharts.com/lib/style.css" type="text/css">
  <script src="https://www.amcharts.com/lib/3/amcharts.js"    type="text/javascript"></script>
  <script src="https://www.amcharts.com/lib/3/serial.js" type="text/javascript"></script>

  <!-- cutom functions -->
  <script>
AmCharts.loadJSON = function(url) {
  // create the request
  if (window.XMLHttpRequest) {
    // IE7+, Firefox, Chrome, Opera, Safari
    var request = new XMLHttpRequest();
  } else {
    // code for IE6, IE5
    var request = new ActiveXObject('Microsoft.XMLHTTP');
  }

  // load it
  // the last "false" parameter ensures that the code will wait before the
  // data is loaded
  request.open('GET', url, false);
  request.send();


 // parse and return the output
  return eval(request.responseText);
};
  </script>

  <!-- chart container -->
  <div id="chartdiv" style="width: 600px; height: 300px;"></div>

  <!-- the chart code -->
  <script>
var chart;

// create chart
AmCharts.ready(function() {

  // load the data
  var chartData = AmCharts.loadJSON('data.php');

  // SERIAL CHART
  chart = new AmCharts.AmSerialChart();
  chart.pathToImages = "http://www.amcharts.com/lib/images/";
  chart.dataProvider = chartData;
  chart.categoryField = "datetime";
  chart.dataDateFormat = "H:m";

  // GRAPHS

  var graph = new AmCharts.AmGraph();
  graph.valueField = "temp";
  graph.bullet = "round";
  graph.bulletBorderColor = "#FFFFFF";
  graph.bulletBorderThickness = 2;
  graph.lineThickness = 2;
  graph.lineAlpha = 0.5;
  chart.addGraph(graph);


 // CATEGORY AXIS
  chart.categoryAxis.parseDates = true;

  // WRITE
  chart.write("chartdiv");
});

  </script>

</body>
</html>

我在浏览器控制台中收到以下错误:

SyntaxError: expected expression, got '<' at :5:3

我不知道为什么我会这样做。有人可以帮忙吗?

感谢

0 个答案:

没有答案