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

Exploring the World of Popper.js Modifiers

Within our React and Typescript application, we integrate the react-datepicker library, which utilizes popper.js. Attempting to configure PopperModifiers according to the example provided here: . Despite replicating the exact setup from the example, a typ ...

Displaying Hierarchical Data with AngularJS and ng-repeat

Recently, I've been working on finding an elegant solution to represent hierarchical data in my application. Specifically, I have implemented a slide effect for bootstrap badges that showcase sub-categories using AngularJS. With some guidance from th ...

Sentry platform is failing to record network-related problems

Incorporating Sentry into my Next.JS application has allowed me to easily detect JavaScript errors such as reference or syntax issues on the Sentry platform. Unfortunately, I have encountered some challenges as Sentry is not logging any network-related er ...

I am looking to retrieve a particular entry from a JSON data array and make some modifications to it

Initially, I fetched JSON data from the web server using the following code: $.getJSON(url,function(){ //my callback function; }); Now, I have received the data in the format shown below: {entries:[{title:'foo',id:'UUID',finished:nul ...

Experience the simplicity of running basic Javascript Scratch code within IntelliJ IDEA Ultimate

Is there a straightforward way to run and debug a basic JavaScript code in IntelliJ Idea Ultimate without the need for additional setup like creating an HTML file or npm project? I'm looking to avoid boilerplate tasks and wondering if there's an ...

Having trouble with the JavaScript DOM rewrite for aligning text?

function modifyTextAlignment(){ document.getElementById("th1").style.textAlign = "right"; } #th1{ text-align:left; } <table> <tr><center><th colspan="2" id="th1">List of Important Emergency Contacts</th><center></tr& ...

The function failed to obtain JSON data from the generated URL

I want to fetch the latest local weather details using a weather API. Below is the code I am working with: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> function generateUrl() { var ap ...

Generate a separate JSON object for each row in the CSV file

I am currently working on adjusting my code to save each row of a csv file as its own json file, which will then be posted online. I have the process of creating structured json data down and formatting it correctly, but I am struggling with looping throug ...

Exploring ways to efficiently test the nested promises in an Angular service function

Here is a snippet of what my service implementation looks like: TestService.initializeDefaults = function() { var qPromise = $q.defer(); $q.all({ localResource: localResource.fetch(), item: itemResource.fetch() }).then(functio ...

Confirm that only the days of the present month are eligible for selection

I have been given the responsibility of validating a date field that is populated when an invoice is created. The date field consists of a text box and three button objects allowing users to select a date from a calendar, input today's date, or remove ...

Tips for configuring CakePHP to trigger the second submit button when the enter key is pressed

My form includes two submit buttons: "cancel" and "find." While both buttons work correctly when clicked, pressing the enter key always triggers the submission of "cancel." I don't want to change the button order in the form. To address this issue, I ...

Eliminating numerical data from a JSON output in Laravel version 9

Having some issues with the JSON response I'm receiving. On making an API call for a user (id:1), the response is as expected. However, when changing the user (e.g. id:2), the response includes additional identifiers. Any thoughts on this? Response ...

Tips for accessing information from an Angular Resource promise

I am currently facing an issue when trying to read data from an angular promise that was returned. Before, I had the following code: var data = category.get({id:userid}); Later, I realized that the data being returned was an unresolved promise. So, I ma ...

Setting up Datatables using AngularJS

I am working on a controller that organizes song rankings based on sales data. Upon initialization, the controller automatically sends an HTTP GET request to retrieve all the songs needed for display (currently set at the top 20 songs). If I ever need to a ...

Transmitting keys and data from Sails.js to Angular via streaming

In my current setup, I am using an angular frontend to fetch data from a sails backend through the sails-mysql adapter and display it in a ui-grid. However, due to the large size of the dataset, there is a noticeable delay in loading the data before the pa ...

Bringing in additional elements, ensure that there is only a single main root element

Apologies for the beginner question. I am facing an issue while trying to display a .vue file with parent and children components, resulting in a "more than one root element" error. It seems strange to me because the imported components are supposed to be ...

Guide on how to assign a masterpage DOM element to a content page using JavaScript

Within an ASP.NET master page, there is a specific div element that I want to hide in one of its content pages. To achieve this, I included the following JavaScript code at the end of the content page: if (document.getElementById('sitemap')) { ...

What is the best way to iterate through a puppeteer selector's response in a loop?

So, by using page.evaluate I can accomplish the following: await page.evaluate(function() { var links = document.querySelectorAll('a'); for (var i = 0; i < links.length; i++) console.log(links[i].href); }); However, I am interested in a ...

creating a JSON array within a function

I am currently developing an Angular application and working on a component with the following method: createPath(node, currentPath = []){ if(node.parent !==null) { return createPath(node.parent, [node.data.name, ...currentPath]) } else { retu ...

What is the best way to include keys in my JSON data, rather than just values?

I've encountered an issue with the PrimeVue datatable I created, as it is only showing empty rows. After investigating, I believe the problem lies in my JSON data structure, where the fields do not have keys. What modifications should be made to stan ...