简体   繁体   中英

ASP.NET MVC - Uncaught ReferenceError: jQuery is not defined even if I'm including the library

I'm using ASP.NET MVC 4 and I'm trying to pass a value from my JavaScript to my Controller Action. Here's what I'm trying to do in my JavaScript :

function DoubleClick() {
    debugger;
    var id = 1;
    $.ajax({
        type: "POST",
        url: "/Home/GetAppId",
        data: { id: id}
    });
}

And my action (really simple action) :

public JsonResult GetAppId(int id)
{
    //some code will be included here
}

In my layout template, I'm including correctly my scripts (actually I'm using JS in some ohter pages and it works) :

    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.validate.globalize.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/jquery-ui-1.10.4.custom.min.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.custom.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.core.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.ui.datepicker.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/DatePickerReady.js")" type="text/javascript"></script>

When I'm opening the Chrome dev tool (F12), I'm seeing the following error message in the console tab :

Uncaught ReferenceError: jQuery is not defined

I can't really see where the problem is. Any idea?

jQuery.Validate uses jQuery.

<script src="@Url.Content("~/Scripts/jquery.validate.globalize.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.js")" type="text/javascript"></script>

Should be like this:

   <script src="@Url.Content("~/Scripts/jquery.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.globalize.min.js")" type="text/javascript"></script>

As to why your JavaScript is not posting back the Value that is another error.

In Ajax you using "POST". Put a HttpPost Attribute on your method.

[HttpPost]
public JsonResult GetAppId(int id)
{
    //some code will be included here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM