是否可以获得两个不同的json输出


is it possible to get two different json output

是否可以在一个页面结果集上获得两个json输出

我必须通过使用ajax将数据传递到另一个页面来填充数据网格和图表,并从单个mysql查询中获得两种类型的json结果集,当我试图返回json时,它无法处理

这是我的结果.php代码,其中将生成json,

include('connection.php');
if (isset($_POST)) {
    $rep_date1 = $_POST['date1'];
    $date1 = date("Y-m-d", strtotime($rep_date1));
    $rep_date2 = $_POST['date2'];
    $date2 = date("Y-m-d", strtotime($rep_date2));
    $sql = mysql_query("SELECT * FROM infra.prob_report WHERE prob_rept_date    BETWEEN '$date1' AND '$date2'");
    $rows = array();
    while ($row = mysql_fetch_assoc($sql)) {
        $nestedData = array();
        $nestedData[] = $row["rep_id"];
        $nestedData[] = $row["prob_rept_date"];
        $nestedData[] = $row["prob_equip_name"];
        $nestedData[] = $row["prob_rept_name"];
        $nestedData[] = $row["prob_desc"];
        $data[] = '<tr><td>'.$row["rep_id"].
        '</td><td>'.$row["prob_rept_date"].
        '</td><td>'.$row["prob_equip_name"].
        '</td><td>'.$row["prob_rept_name"].
        '</td><td>'.$row["prob_desc"].
        '</td></tr>';
        $point = array("label" => $row['prob_equip_name'], "y" => $row['rep_id']);
        array_push($data_points, $point);
    }
    echo json_encode($data); //json output populating data-grid
    echo json_encode($data_points); //json output populating chart
}

这是我的handle.php,我的处理脚本在这里运行

<script>
    $(document).ready(function() {
        $('#submit').click(function() {
            var name = $("#name").val();
            event.preventDefault();
            $.ajax({
                type: "POST",
                url: "new_prob_submit.php",
                data: {
                    'date1': $('#picker1').val(),
                    'date2': $('#picker2').val()
                },
                dataType: "json",
                success: function(data) {
                    $('#tbdy').html(data);
                    $.getJSON("result.php", function(result) {
                        var chart = new CanvasJS.Chart("chartContainer", {
                            data: [{
                                dataPoints: result
                            }]
                        });
                        chart.render();
                    });
                }
            });
        });
    });
</script>

只做一件事。

在php中

echo json_encode(
    array(
        'data' => $data, 
        'dataPoints' => $data_points
    )
); //json output populating data-grid and populating chart

在javascript 中

success:function(result){ 
result.data;
result.dataPoints;
}