开发者

asp.net mvc 3 highchart

In addition to my previous question, I tried to use the same working code (for MVC2) in a MVC3 project. I figured out it's not possible 开发者_运维百科to use the jQuery.getJSON method. So I tried to use the $.post and $.ajax method instead, but again facing a problem.

In both methods I get an error "Jscript: JB is empty or not an object"

$.post("Home/GetLineData", null, function (items) {                
            var series = [];
            jQuery.each(items, function (itemNo, item) {
                //Get the items from the JSON and add then                 
                //to the data array of the series
                series.push({
                    name: item.Key,
                    data: item.Value
                })
            });
            options.series = series;
            chart = new Highcharts.Chart(options);
            chart.render();
        });

$.ajax({
            type: "POST",
            dataType: "json",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            url: "/Home/GetLineData",
            cache: false,
            succes: function (data) {
                var series = [];
                jQuery.each(data, function (itemNo, item) {
                    //Get the items from the JSON and add then                 
                    //to the data array of the series
                    series.push({
                        name: item.Key,
                        data: item.Value
                    })
                });
                options.series = series;
                //Create the chart
                chart = new Highcharts.Chart(options);
                chart.render();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });

Thanks in advance for helping me out (again :-s).


The problem was in the HTML, so the container element was not found. So now both methods are working!

Jorelie.


BTW - you can use getJSON in MVC 3.0, but your controller method has to return the JSON object with a second parameter like so :

Json(result, JsonRequestBehavior.AllowGet);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜