Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSON到jQuery图表_Javascript_Php_Jquery_Mysql_Json - Fatal编程技术网

Javascript JSON到jQuery图表

Javascript JSON到jQuery图表,javascript,php,jquery,mysql,json,Javascript,Php,Jquery,Mysql,Json,我有一个PDO脚本,它从SQL表中回显JSON 我试图在jQuery图表中显示JSON信息,但没有成功 我在chrome调试器中得到一个错误,它引用了下面的第一行jQuery代码(var json) 功能参考: Uncaught SyntaxError: Unexpected identifier angular.js:11598 ReferenceError: Index is not defined at eval (eval at <anonymous> (ht

我有一个PDO脚本,它从SQL表中回显JSON

我试图在jQuery图表中显示JSON信息,但没有成功

我在chrome调试器中得到一个错误,它引用了下面的第一行jQuery代码(var json)

功能参考:

    Uncaught SyntaxError: Unexpected identifier
angular.js:11598 ReferenceError: Index is not defined
    at eval (eval at <anonymous> (http://localhost/assets/global/plugins/jquery.min.js:2:2622), <anonymous>:2:2)
    at eval (native)
    at http://localhost/assets/global/plugins/jquery.min.js:2:2622
    at Function.m.extend.globalEval (http://localhost/assets/global/plugins/jquery.min.js:2:2633)
    at m.fn.extend.domManip (http://localhost/assets/global/plugins/jquery.min.js:3:23159)
    at m.fn.extend.append (http://localhost/assets/global/plugins/jquery.min.js:3:20620)
    at null.<anonymous> (http://localhost/assets/global/plugins/jquery.min.js:3:22151)
    at m.access (http://localhost/assets/global/plugins/jquery.min.js:3:3399)
    at m.fn.extend.html (http://localhost/assets/global/plugins/jquery.min.js:3:21736)
    at compile (http://localhost/assets/global/plugins/angularjs/plugins/angular-ui-router.min.js:7:21866) <div ui-view="" class="fade-in-up ng-scope">(anonymous function) @ angular.js:11598$get @ angular.js:8548$ @ angular.js:8219v @ angular.js:7726g @ angular.js:7075(anonymous function) @ angular.js:6954k @ angular-ui-router.min.js:7(anonymous function) @ angular-ui-router.min.js:7$get.l.$broadcast @ angular.js:14707x.transitionTo.x.transition.I.then.x.transition.x.transition @ angular-ui-router.min.js:7(anonymous function) @ angular.js:13175$get.l.$eval @ angular.js:14388$get.l.$digest @ angular.js:14204(anonymous function) @ angular.js:14427e @ angular.js:4902(anonymous function) @ angular.js:5282

我做错了什么?

指向错误行#,函数参考,并提供更多上下文。不要粘贴切碎的代码并期望得到答案!意外标识符指的是jQuery代码的第一行(“var json”行),我想不出更多的代码可以发布,因为它似乎与问题无关,我可能错了,但这似乎是负责的代码。这段代码似乎有点错误。您希望
initCharts
方法属于
json
对象吗?还是
json
iLife?你为什么希望ajax是同步的呢?老实说,我对这一点还不太熟悉,我正在尝试的是将php中的JSON信息输入到数据库的“数据”中chart@Bugier84您是否注意到您初始化了
var json=function(…
,然后将其重新初始化为
var json=null
?我可以建议您使用更“自我解释”的变量名称来帮助调试吗?
<?php


$dbh = new PDO("mysql:host=localhost;dbname=test", "root", "");
$statement=$dbh->prepare("SELECT * FROM pdotable");
$statement->execute();
$results=$statement->fetchAll(PDO::FETCH_ASSOC);
$json=json_encode($results, JSON_PRETTY_PRINT);

header('Content-type: application/json');

echo $json;
?>
var json = (function () {
                var json = null;
                $.ajax({
                    'async': false,
                    'global': false,
                    'url': 'pdo/phpinfo.php',
                    'dataType': "json",
                    'success': function (data) {
                        json = data;
                    }
                });
                return json;
            });

        initCharts: function() {

            if (Morris.EventEmitter) {
                // Use Morris.Area instead of Morris.Line
                dashboardMainChart = Morris.Area({
                    element: 'sales_statistics',
                    padding: 0,
                    behaveLikeLine: false,
                    gridEnabled: false,
                    gridLineColor: false,
                    axes: false,
                    fillOpacity: 1,
                    data:json,
                lineColors: ['#399a8c', '#92e9dc'],
                xkey: 'period',
                ykeys: ['sales', 'profit'],
                labels: ['Sales', 'Profit'],
                pointSize: 0,
                lineWidth: 0,
                hideHover: 'auto',
                resize: true
            });

        }
    },