1

Am trying to draw pie chart by getting data from sql server. The issue is that when I run the code I get error "Failed to load resource: the server responded with a status of 404 (Not Found)". The service is under ClientsService Here is my code

$(document).ready(function () {

           $.ajax({
               type: "POST",
               dataType: "json",
               contentType: "application/json; charset=utf-8",
               url: "/Clients/GetStoresCount",
               data: "",
               success: function(data){
                   chartData;
               },
               error: function(){
                   alert("Error Loading data! please try again.");
               }
           }).done(function (){
               google.charts.setOnLoadCallback(drawChart);
           });
       });
      function drawChart() {

        var data =new google.visualization.DataTable();
         data.addColumn('string','CityID');
         data.addColumn('string','Stores');
         for(var i = 0; i < chartData.length; i++){
             if(i != 0){
             data.addRow([chartData[i].CityID,chartData[i].Stores]);
         }
         }
        var chart = new google.visualization.PieChart(document.getElementById('piechart'));
           draw(data, {title: "Stores Per region"});
          chart.draw(data, options);

service for getting data from sql is:
    public IEnumerable<Store> GetStoresCount()
        {
            using (IDbConnection conn = Connection)
            {
                string sQuery = "; exec GetStoreCountPerRejion";

                var s = conn.Query<Store>(sQuery);
                return s;
            }
        }
  • My guess would be, either your URL is wrong or your HTTP method (or both ^^). Check the *complete* URL in your browsers dev tools (network tab), after execution of your function. Is the API endpoint really a POST method? The routes name ends with 'GetStoresCount' (is it a GET method maybe?), your `data` does not contain anything but an empty string (`data: ""`). Btw, your ajax.error callback provides parameters (XMLHttpRequest, textStatus, errorThrown) you could use to check for a more detailed error message - [check this example](https://stackoverflow.com/a/2833968/2590375) – nilsK Jun 01 '22 at 12:42
  • `success` and `error` callbacks are obsolete, please check the docs, if you are running on a newer version (>= 1.8). – nilsK Jun 01 '22 at 12:45
  • @nilsk am trying to call as Service to get data and draw a pie chart – Edwin Macharia Jun 01 '22 at 12:54
  • This suggestion worked for me. – Edwin Macharia Dec 15 '22 at 04:56

0 Answers0