legobear154
legobear154

Reputation: 431

PHP, ajax, and JQplot

I have a php file that I reads my MySQL database and returns a JSON Array. The JSON array is then suppose to be saved to a JavaScript variable and then JQPlot is suppose to load it. Every time I run the JavaScript to get the data and create the chart I get "Uncaught #" in the Google Chrome JavaScript console. Any ideas why I might be getting this error? The response I get after the ajax call is this:

[["Internet Explorer",0],["Firefox",0],["Safari",0],["Opera",0],["Chrome",1],["Other",0]]

which is correct as far as I could tell.

Here is my Javascript as well:

    $(document).ready(function(){
        var browsers = $.post("stats.php", {action:"getbrowsers"});
        var plot1 = jQuery.jqplot ("browsers_pie", [browsers], { 
            seriesDefaults: {
                renderer: jQuery.jqplot.PieRenderer, 
                rendererOptions: {
                    showDataLabels: true
                }
            }, 
            legend: { show:true, location: "e" }
        });
     });

Upvotes: 2

Views: 935

Answers (1)

Marc B
Marc B

Reputation: 360732

You haven't told jquery that you're expecting JSON back, so you're just getting a plain string that happens to contain JSON, not a data structure decoded from the JSON string.

    var browsers = $.post("stats.php", {action:"getbrowsers"}, 'json');
                                                             ^^^^^^^^

Upvotes: 3

Related Questions