User588233
User588233

Reputation: 491

ASP.Net - Invalid Json String

I have been developing a web application in ASP.Net, which should return information from a database via a Web Service class. From there, I wish to bind the data to a Google Combo chart.

The data can be bound to a grid view, so I know the method to call from the database is working, but when I try to bind it to the chart I receive the error message:

Invalid Json String:

!Doctype HTML

html lang = "en"

This is my first time working with javascript, so I assume that my javascript methods are accessing the wrong data, but I'm not sure where I'm going wrong. If anybody could let me know what I have done wrong, it would be appreciated.

DEFAULT.ASPX

    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

<html>
    <head>
            <script type="text/javascript" src="https://www.google.com/jsapi"></script>
            <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
            <script type="text/javascript">

                google.load("visualization", "1", { packages: ["corechart"] });
                google.setOnLoadCallback(drawVisualization);

                function drawVisualization() {
                    var jsonData = $.ajax({
                        url: "Default.aspx/GetChartData",
                        dataType: "json",
                        async: false
                    }).responseText;

                    var data = new google.visualization.DataTable(jsonData);

                    var options = {
                        title: 'Chart Title',
                        vAxis: { title: 'Scores %' },
                        hAxis: { title: 'Counties' },
                        seriesType: 'bars',
                        series: {
                            2: {
                                targetAxisIndex: 1
                            },
                            vAxes: {
                                1: {
                                    title: '1',
                                    textStle: { color: 'red' }
                                }
                            }
                        }
                    };

                    var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
                    chart.draw(data, options);
                }
        </script>
    </head>
    <body>
                <asp:GridView ID="Grid1D" runat="server"
                    AutoGenerateColumns = "true" Font-Names = "Arial"
                    Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B" 
                    HeaderStyle-BackColor = "green" AllowPaging ="true"  
                    PageSize = "10" Caption = "1-Dimensional Array">
                </asp:GridView>

                <div id ="chart_div" style="width:500px;height:400px"></div>
                 <asp:Literal ID="ltScripts" runat="server"></asp:Literal> 
    </body>
</html>

Upvotes: 0

Views: 228

Answers (1)

Dietz
Dietz

Reputation: 578

Sounds a lot like your call to Default.aspx/GetChartData returns an error page from the IIS that is hosting it. You should take a look at your jsonData variable, as it is anything but json.

Upvotes: 1

Related Questions