Uncaught TypeError: undefined is not a jquery.unobtrusive-ajax.js function

In my mvc 4 web application, I get the following error: "Uncaught TypeError: undefined is not a jquery.unobtrusive-ajax.js: 115 function"

on this line we have

$("a[data-ajax=true]").live("click", function (evt) { evt.preventDefault(); asyncRequest(this, { url: this.href, type: "GET", data: [] }); }); 

I found that many people got the same error and read messages. Almost all of them recommend reordering the scripts of jquery and others that I tried for a long time, but nothing removes this error.

I currently have css and scripts in the following order in the chapter section. Can anyone find any problems? thanks

 <link href="/Content/main/css/bootstrap.css" rel="stylesheet"/> <link href="/Content/UiDatePicker.css" rel="stylesheet"/> <link href="/Content/Site.css" rel="stylesheet"/> <script src="/Scripts/modernizr-2.5.3.js"></script> <script src="/Scripts/jquery-1.9.1.js"></script> <script src="/Scripts/jquery-ui.js"></script> <script src="/Scripts/bootstrap.js"></script> <script src="/Scripts/respond.js"></script> <script src="/Content/main/js/General.js"></script> <script src="/Scripts/jquery.unobtrusive-ajax.js"></script> <script src="/Scripts/jquery.validate.js"></script> <script src="/Scripts/jquery.validate.unobtrusive.js"></script> 
+5
source share
1 answer

.live() deprecated in jQuery 1.7 and was removed in jQuery 1.9. You can use instead . On () :

 $("a[data-ajax=true]").on("click", function (evt) { 

Or, if elements are added dynamically:

 $(document).on('click', "a[data-ajax=true]", function (evt) { 

Note. Despite the fact that you can fix all these problems in unobtrusive-ajax.js, it is better to download a newer version, and all these problems will be fixed (if this version exists at all, of course).

+3
source

Source: https://habr.com/ru/post/1205854/


All Articles