简体   繁体   English

getJSON函数没有执行

[英]getJSON function is not executing

I am trying to call a simple data.json file, code is given below, 我试图调用一个简单的data.json文件,代码如下,

alert("outside");
    $(document).ready(function () {
        alert("inside");
        $("#myButton").click(function () {

            var options = {
                chart: {
                    renderTo: 'container',
                    type: 'spline'
                },
                series: [{}]
            };
        });


        $.getJSON('data.json', function (data) {
            alert("read");
            options.series[0].data = data;
            var chart = new Highcharts.Chart(options);
        });

    });

and below is my data.json content 以下是我的data.json内容

[{"series_name":"Actual","period_name":"Q1 / 2013","period_final_value":"17"},
{"series_name":"Actual","period_name":"Q2 / 2013","period_final_value":"15"}]

I tried by inserting alerts as well, it seems getJSON doesn't read my json file. 我尝试插入警报,似乎getJSON没有读取我的json文件。 Since I am new to JSON, I might be wrong in calling function,any help will be greatly appreciated.I have also referred highcharts, my main aim is to plot the graph on highcharts by reading the value from json file. 由于我是JSON的新手,我可能在调用函数时出错,任何帮助都会非常感激。我还提到了highcharts,我的主要目的是通过读取json文件中的值来绘制高图上的图形。

As a first step, try this code to find out what the error is. 作为第一步,尝试此代码以找出错误是什么。

Also look in the networking tab of Chrome dev tools to find out what network activity is taking place. 另请查看Chrome开发工具的网络标签,了解正在进行的网络活动。

$.getJSON("data.json", function() {

     alert("success");

})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM