小编sno*_*ite的帖子

多个JSON对象响应

我有一个情况,我有一个下拉的PHP文件'A'.当我从该下拉列表中选择一个值时,进行ajax调用并触发不同的php文件B. 在那个文件中,我做数据库提取,并形成两个json对象.这两个json对象是我需要绘制2个不同的数据表和2个不同的图表.

  1. 当我在'B'中回应一个json对象时,我将其作为对'A'中ajax调用的响应

  2. 如果我在B中回显两个json对象,我甚至无法得到响应.

  3. 对于单个json对象响应,我可以绘制datatable并可以使用javascript操作json对象并希望绘制图表

请告知如何处理这种情况来自文件B的代码

        $json = json_encode($tot_categ);
        $json_percent = json_encode($tot_que_percent);
            $cols_percent = array(
                array( 'id' => 't', 'label' => 'Title', 'type' => 'string'),
                array( 'id' => 'n', 'label' => 'Neutral(+) ', 'type' => 'string'),
                array('id' => 'a', 'label' => 'Agree', 'type' => 'string'),
                array('id' => 'ne', 'label' => 'Neutral(-)', 'type' => 'string'),
                array('id' => 'd', 'label' => 'Disagree', 'type' => 'string'),

        );

        $jcols_percent = json_encode($cols_percent);
        //JSON format accepted by Google tables
        $r_percent= "{cols:".$jcols_percent.','."rows:".$json_percent."}";
        //echo (JSON.stringify($r_percent));
        // echo $r_percent; …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax google-visualization

3
推荐指数
1
解决办法
3991
查看次数

标签 统计

ajax ×1

google-visualization ×1

javascript ×1

php ×1