我正在尝试从一个php页面检索数据以在一个flot图表中使用。我在ajax调用中遇到问题,我无法弄清楚。来自php文件的Ajax调用
下面是一些我的PHP的:
//Sort data into groups for chart
foreach($querieResult as $entry){
if ($entry['GroupName'] == 'Blue'){
$date = strtotime($entry['Date'] . ' UTC')*1000;
$BlueData[] = array($date, $entry['OverallAverageHourlyEpisodes']);
}
}
//Put all data into single array to pass to JS file
$mergedData[]= array('label' => "Blue Team Data", 'data' => $BlueData);
//JSON encode data for JS file
echo json_encode($mergedData);
,输出:
[{"label":"Blue Team Data","data":[[1373500800000,"1.57"],[1381276800000,"12.89"],[1377475200000,"28.04"]]}]null
这里是我的ajax:
$.ajax({
url:"getTeamPerformance.php",
method: 'GET',
cache: false,
dataType: 'json',
success: function(data){
alert(data.label);
alert(data.data);
},
error: function(errorGiven){
document.write(errorGiven);
}
});
我想看看如果数据传递通过这样的成功,我只是有一个戒备。
当此运行,我得到的输出:
[object Object]
任何帮助,将不胜感激!
尝试'警报(JSON.stringify(数据));''或者更好地使用'console.log(data)' – PSL
同意@PSL - 先记录你的数据,看看它是什么,我看到你的回调中有一个**数组对象,所以显然'data.label'不起作用。你可能需要'data [0] .label' - 但是首先记录它,这有很大的帮助。 – tymeJV