JQuery - $ is not defined

juan miguel nieto 1 Reputation point
2022-12-12T04:13:22.753+00:00

I'm receiving this kind of error on my script any idea how to debug this? I tried a few solutions like the latest script should be at the top

$(document).ready(function () {

$.ajax({  
    type: "POST",  
    url: 'Home/DashBoardcount',  
    data: JSON.stringify({}),  
    contentType: "application/json:charset=utf-8",  
    dataType: "json",  
    success: function (json) {  
        var values = json.DashBoardcount;  
        var passcount = parseInt(values[0]);  
        var failcount = parseInt(values[1]);  

    }  
})  

});

Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares in May, 2020'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
accessibility: {
point: {
valueSuffix: '%'
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [{
name: 'Chrome',
y: 70.67,
sliced: true,
selected: true
}, {
name: 'Edge',
y: 14.77
}, {
name: 'Firefox',
y: 4.86
}, {
name: 'Safari',
y: 2.63
}, {
name: 'Internet Explorer',
y: 1.53
}, {
name: 'Opera',
y: 1.40
}, {
name: 'Sogou Explorer',
y: 0.84
}, {
name: 'QQ',
y: 0.51
}, {
name: 'Other',
y: 2.6
}]
}]
});

View ( Charts):
@{
ViewBag.Title = "Charts";
}

<script src="~/Scripts/Dashboard charts/Dashboard.js"></script>

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
Pie charts are very popular for showing a compact overview of a
composition or comparison. While they can be harder to read than
column charts, they remain a popular choice for small datasets.
</p>
</figure>

Controller:
public ActionResult Charts()
{
return View();
}

    public JsonResult DashBoardcount()  
    {  
        try  
        {  
            string[] DashBoardcount = new string[2];  

            SqlConnection con = new SqlConnection(connectionString);  
              


            con.Open();  
            SqlCommand cmd = new SqlCommand("Select count([YearGraduate]) as pass,(select count([YearGraduate]) from [dbo].[Student] where YearGraduate='2022'and Program='CE' and BoardScore >=60.00) as fail from [dbo].[Student] where  YearGraduate='2022' and Program='CE' and BoardScore <=59.99", con);  
            DataTable dt = new DataTable();  
            SqlDataAdapter cmd1 = new SqlDataAdapter(cmd);  
            cmd1.Fill(dt);  

            if(dt.Rows.Count == 0)  
            {     
                DashBoardcount[0] = "0";  
                DashBoardcount[1] = "0";  

            }  
            else  
            {  
                DashBoardcount[0] = dt.Rows[0]["pass"].ToString();  
                DashBoardcount[1] = dt.Rows[0]["fail"].ToString();  
            }  
            return Json(new { DashBoardcount }, JsonRequestBehavior.AllowGet);  
        }  
        catch (Exception ex)  
        {  
            throw ex;  
        }  
    }  
}  

}

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-12-12T06:01:30.103+00:00

    Hi @juan miguel nieto ,
    Since you are using JQuery ajax, you need to use the JQuery library.

    <scr ipt src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></scr ipt>  
    

    269561-image.png
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-12-12T18:46:29.447+00:00

    your code needs to come after the jquery script include. use browsers view source to check. of the script include is at the end of the page, and you need to use a script section defined in the master page.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.