Ajax从php错误中获取数据

时间:2016-12-08 11:41:44

标签: javascript ajax

在php文件(ajax_chart.php)中我有这个



$search=$_POST['present'];
if(!empty($search)){
      
        include '../main_includes/connect_db.php';
        $present_day = date("d");
        $present_month = date("m");
        $present_year = date("y");
        for ($i=0;$i<=23;$i++){
        $total_visitors_present=[];
        $query="SELECT * FROM visitors WHERE visitor_day=$present_day AND visitor_hour=$i AND visitor_minute<=59   ";
        $select_query= mysqli_query($connect, $query);
        $num_visitors[$i]= intval(mysqli_num_rows($select_query));
        array_push($total_visitors_present, $num_visitors);
        
        }
        echo json_encode($total_visitors_present[0]);
        
}
&#13;
&#13;
&#13;

在脚本标记中的另一个php文件(charts.php)中,我有以下Ajax代码

&#13;
&#13;
$.ajax({
                url: 'includes/ajax_chart.php',
                data:{present:'present'},
                type: 'POST',
                success: function (data) {
                     if(!data.error){
                        console.log(data); 
                     }   
                    }
            });
&#13;
&#13;
&#13;

控制台输出很奇怪。

虽然我期望输出的是以下数组 [0,0,0,0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0] 我究竟做错了什么? 我如何用ajax检索数组?

0 个答案:

没有答案