2

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" }
        });
     });

1 Answer 1

3

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');
                                                             ^^^^^^^^
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.