I changed everything below from .live to .on and modified the code per many of the discussions I have found, but when I run the code in Visual Studio, I keep getting the below error:
Unhandled exception at line 115, column 5 in http://'server':6665/Scripts/jquery.unobtrusive-ajax.js
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'live'
And the file that Visual Studio is showing as wrong is jquery.unobtrusive-ajax.js [dynamic] <-- Where is this file? It is highlighting the old code with the deprecated .live method before I changed everything below...
I also install the migrate package and that did not work.
$(document).on("click", "a[data-ajax=true]", function (evt) {
evt.preventDefault();
asyncRequest(this, {
url: this.href,
type: "GET",
data: []
});
});
$(document).on("click", "form[data-ajax=true] input[type=image]", function (evt) {
var name = evt.target.name,
$target = $(evt.target),
form = $target.parents("form")[0],
offset = $target.offset();
$(form).data(data_click, [
{ name: name + ".x", value: Math.round(evt.pageX - offset.left) },
{ name: name + ".y", value: Math.round(evt.pageY - offset.top) }
]);
setTimeout(function () {
$(form).removeData(data_click);
}, 0);
});
$(document).on("click", "form[data-ajax=true] :submit", function (evt) {
var name = evt.target.name,
form = $(evt.target).parents("form")[0];
$(form).data(data_click, name ? [{ name: name, value: evt.target.value }] : []);
setTimeout(function () {
$(form).removeData(data_click);
}, 0);
});
$(document).on("submit", "form[data-ajax=true]", function (evt) {
var clickInfo = $(this).data(data_click) || [];
evt.preventDefault();
if (!validate(this)) {
return;
}
asyncRequest(this, {
url: this.action,
type: this.method || "GET",
data: clickInfo.concat($(this).serializeArray())
});
});
Thanks! Tony
I added jquery migrate plugin and included that in bundles.config file
PM> Install-Package jQuery.Migrate
and then in bundlesConfig.cs
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery-migrate-1.2.1.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
.Live was removed from jquery 1.9+ http://jquery.com/upgrade-guide/1.9/
You should upgrade jquery.unobtrusive-ajax.js
as it is dependent on an older jquery version.
I recently had to make some modifications to a C# project that experienced errors with $("foo").live(). The change to $("foo").on() also presented an error for me due to the dynamic script.
You are seeing the old code because it is cached. For IE 11 do the following: Internet Options -> General -> Browsing History -> Settings -> Check for newer versions very time I start IE. Or, every time you access a page if you like.
User contributions licensed under CC BY-SA 3.0