我在OpenLayers上有一个热图应用程序,用户输入两个日期和时间间隔,并选择是否要查看这两个日期时间之间的所有数据,或者根据每小时/每日/每周/每月间隔查看它们。但是,当我输入两个日期和时间作为输入并尝试可视化数据时,我只能可视化这两个间隔之间的所有数据。每当我从我的HTML下拉菜单中选择每小时,每天,每周等时,按下获取查询按钮,我在Ajax POST消息中出现错误。这可能是什么原因?代码如下:
HTML Post部分:
$(document).ready(function(){
// ajaxForm submission
$('#ajaxForm').submit(function() {
$.ajax({
type: 'POST',
url: 'heatQuery.php',
//url: 'http://localhost/heatQuery.php',
data: $(this).serialize(),
dataType: 'json',
success: function(response)
{
// update the points for heatmap layer
updateHeatMap(response);
},
error: function(errorMsg)
{
alert('Error in Ajax POST');
}
});
return false;
});
});
PHP部分:
setupDB.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "myuser";
$mysql_password = "mypassword";
$mysql_database = "mydatabase";
$bd = mysql_connect($mysql_hostname, $mysql_user) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");
?>
heatQuery.php
<?php
include 'setupDB.php';
$coords_array = array();
function getPoints($dateTimeBeg,$dateTimeEnd)
{
$ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";
$result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
if($result)
{
$num_of_rows = mysql_num_rows($result);
if($num_of_rows > 0)
{
while($row = mysql_fetch_row($result))
{
array_push($coords,array($row[0],$row[1]));
}
array_push($coords_array,$coords);
}
}
}
$hours = array(1 => '00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00');
$dateBeg = isset($_POST['date1']) ? $_POST['date1'] : "";
$dateEnd = isset($_POST['date2']) ? $_POST['date2'] : "";
$dateFreq = isset($_POST['freq']) ? $_POST['freq'] : "";
if($dateBeg && $dateEnd && $dateFreq) // if all variables are set
{
$datetime1 = new DateTime($dateBeg);
$datetime2 = new DateTime($dateEnd);
$interval = $datetime1->diff($datetime2,true);
if($dateFreq == "all")
{
$coords = array();
$timeBeg = $_POST['time1'];
$timeEnd = $_POST['time2'];
$sp = " ";
$dateTimeBeg = $dateBeg.$sp.$timeBeg;
$dateTimeEnd = $dateEnd.$sp.$timeEnd;
$ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";
$result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
if($result)
{
$num_of_rows = mysql_num_rows($result);
if($num_of_rows > 0)
{
while($row = mysql_fetch_row($result))
{
array_push($coords,array($row[0],$row[1]));
}
array_push($coords_array,$coords);
}
}
}else if($dateFreq == "hourly")
{
for($i=1;$i<=24;$i+=1)
{
$coords = array();
$timeBeg = $hours[$i];
$timeEnd = $hours[$i+1];
$dateTimeBeg = $dateBeg.$sp.$timeBeg;
$dateTimeEnd = $dateBeg.$sp.$timeEnd;
$ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";
$result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
if($result)
{
$num_of_rows = mysql_num_rows($result);
if($num_of_rows > 0)
{
while($row = mysql_fetch_row($result))
{
array_push($coords,array($row[0],$row[1]));
}
array_push($coords_array,$coords);
}
}
}
}else if($dateFreq == "daily")
{
for($i=1;$i<=interval;$i+=1)
{
$ses_sql= "SELECT lat,lon FROM `mytable` WHERE calltime >= '$dateTimeBeg' AND calltime <= '$dateTimeEnd'";
$result = mysql_query($ses_sql,$bd) or die('Error: ' . mysql_error());
if($result)
{
$num_of_rows = mysql_num_rows($result);
if($num_of_rows > 0)
{
while($row = mysql_fetch_row($result))
{
array_push($coords,array($row[0],$row[1]));
}
array_push($coords_array,$coords);
}
}
}
}
$coords_json = json_encode($coords_array);
echo $coords_json;
//echo $coords;
mysql_close($bd);
}
?>
编辑:
根据bPratik的要求,我还要为HTML代码提供替代发布错误,其中包含我从服务器获得的错误:
error: function(jqXHR, textStatus, errorThrown)
{
alert('Error in Ajax POST\ntextStatus: ' + textStatus + '\nerrorThrown: ' + errorThrown);
}
尽管如此,我只得到AJAX Post消息中的错误。奇怪的是,mysqld.exe进程运行了一段时间 - 显然它实际上同时检索了查询 - 然后我收到了消息。
答案 0 :(得分:0)
前一段时间解决了这个问题,很快就会发布详情。