ASP.Net - Unexpected JSON Format Error

As I work on my ASP.Net web application, I am encountering an issue with binding data from a database to a Google Combo chart via a Web Service class.

While I can successfully bind the data to a grid view, attempting to bind it to the chart results in the following error message:

Invalid Json String:

!Doctype HTML

html lang = "en"

This is my first experience working with javascript, so I suspect that my JavaScript methods are not accessing the correct data. Any guidance on where I might be making a mistake would be greatly 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>

Answer №1

It appears that the request to Default.aspx/GetChartData is causing an error response from the hosting IIS server. It might be worth examining the contents of the jsonData variable, as it does not seem to contain valid JSON data.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

At the ready stance for a particular grade of students attending a class

I have created a page with a navigation menu that can be scrolled using the wheel mouse. My goal is to ensure that the li item with the 'selected' class is always positioned in the first position on the left. Is there a way to achieve this using ...

In my current project, I've noticed that while everything is being parsed correctly in the JSON data, there is one element that is consistently returning null even though it

Every time I attempt to parse the messages, it consistently returns nil. While occasional errors would be understandable, this recurring issue suggests a deeper problem at play. Reviewing the console output reveals: commitJson(sha: "3665294d1e813d35594d6 ...

Loading Datatables using PHP to send JSON data

I seem to be facing some difficulty in troubleshooting the issue within my code. Currently, I am working on a search script and would like to display the results using Datatables. I have a search form that sends data to my PHP file which then returns a JS ...

Creating a customizable range input for pixel values: a step-by-step guide

I am looking to design a pixel range input. Here is an example: let slider = document.querySelector("input"); slider.addEventListener("change", () => { console.log(slider.value); }); <input type="range" min="5px" max="50px"> However, the r ...

Select the send all text option when making a request

Using ajax, I can dynamically fill a drop-down select menu. My next step is to include all the text from the selected options in my request. <select name=".." > <option value="0"> ... </option> <option value="1"> xxx </option ...

What options are available to enable the user to input information into the v-time-picker component?

I am looking for a solution where users can input digits into the vuetify v-time-picker, while still being able to select the time on the clock. <v-col align-self="center"> <v-menu ref="menuTimeStart" v-model="me ...

Issue: Unable to update reference: The primary argument includes an invalid key

Encountering a curious error on Firebase while working with Vue.js: The process goes smoothly the first time, and I can execute the following function multiple times without any issues. addSpace: function (newSpace) { let userId = firebaseApp.auth(). ...

What is the best way to insert an image in front of text within a table cell that can be identified by its class name?

JavaScript Question: function addFlags(){ while(i < $('.tabledata').length){ var current_val = $('.tabledata').eq(i).text(); arr.push(current_val); $('.tabledata').eq(i).html("<img s ...

Design with Internal Elements

Seeking a pattern similar to the code snippet provided below. Interested in learning how to create MyComponent. render(){ <MyComponent> <MyComponent.Something> These children will be displayed </MyComponent.Something> <MyC ...

Updating the iFrame source using jQuery depending on the selection from a dropdown menu

I want to create a dynamic photosphere display within a div, where the source is determined by a selection from a drop-down menu. The select menu will provide options for different rooms that the user can view, and the div will contain an iframe to showca ...

The never-ending nightmare of acquiring a Facebook Graph token

One of the tasks I regularly undertake for clients is fetching Facebook photos to incorporate into their websites. However, I often encounter a frustrating issue where the photos work for a while and then suddenly stop working. After doing some research o ...

Bot on Discord using Discord.Js that generates unique invites for users

I'm trying to find a way to generate an invite link for users to keep track of invites. The code I have currently is creating the invite for the Bot instead. const channel = client.channels.cache.find(channel => channel.id === config.server.channel ...

Retrieve the values and IDs for every span element within the form

I have been attempting to retrieve all span elements within a form and make them editable input text fields. Once you click away, they should revert back to span elements. I will provide a live example in the attached fiddle. I tried my hand at it, but the ...

ngInfiniteScroll Activates on Every Scroll Occurrence

Implementing ngInfiniteScroll for endless scrolling on my website has required me to set the height of the outer div to a specific value. Without this adjustment, the Infinite Scroll feature activates unintentionally. <div style="height: 1px"> &l ...

What is the best approach to create a JavaScript search filter function spanning two pages?

Page1.html has a form with a drop-down menu containing options Color and Shape. There is also a submit button. Assuming Page2.html displays various shapes like Blue Square, Red Square, Blue Circle, Red Circle, is it feasible to create a JavaScript file th ...

Display of Navigation Bar in Angular is Not Proper

Currently diving into the world of Angular, I've encountered an issue with a material menu that isn't displaying correctly. The expected outcome based on my code should resemble this image: https://i.stack.imgur.com/z70Aq.png This snippet showc ...

Looking for assistance with a simple Javascript program

My program needs to have a for loop and utilize existing input functions (name and number). Additionally, I need to calculate totals. Users should be able to CANCEL and proceed to doc.write where they can enter their name and number. Furthermore, users s ...

implementing AJAX functionality in Laravel when a drop-down item is selected

Hello there, I am a newcomer to the world of coding and I'm currently learning Laravel for a personal project. My goal is to retrieve data from a database based on the selection made in a dropdown menu. Here's the code for the dropdown menu: < ...

Tips for exchanging JSON data between HTML and PHP using jQuery Ajax?

Hello there! I am just starting to learn PHP and jQuery, and I have been experimenting with some code to understand how things work. However, I seem to be having issues with sending data back and forth between my webpage and the PHP file on the server. Her ...

My Tailwind CSS toggle button disappears in dark mode, why is that happening?

<button aria-label="Toggle Dark Mode" type="button" className="lg:inline-flex lg:w-40 md:w-screen p-3 h-12 w-12 order-2 md:order-3" onClick={() => setTheme(theme === 'dark' ? &ap ...