There is no live()
function in jquery 1.9.0, but jquery.unobtrusive.ajax.js is already use this function.
Should I us
Depreciated as of 1.7 and removed as of 1.9. Use on()
instead.
http://api.jquery.com/on/
$("#myButton").on("click", function(){
alert("Clicked");
});
Lots of good info here:
http://www.elijahmanor.com/2012/02/differences-between-jquery-bind-vs-live.html
As for Unobtrusive Ajax, you will need to include a version of jQuery prior to v1.9 where live()
still exists.
If you are referencing the MS CDN,
http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.js http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js
then it does not appear that these directly reference jQuery. Simply include the 1.8 version in your code instead of the 1.9 version.
jquery.migate adds back in the legacy function. This means that jquery.unobtrusive.ajax.js functions as expected.
Reference the jquery.migrate library as per the official blog and there is a nuget pacakge too but obviously you'll need to update your template/layout views.
http://blog.jquery.com/2013/01/31/jquery-migrate-1-1-0-released/
http://nuget.org/packages/jQuery.Migrate/
Javascript console does highlight the issue ...
JQMIGRATE: Logging is active JQMIGRATE: jQuery.fn.live() is deprecated JQMIGRATE: jQuery.fn.andSelf() replaced by jQuery.fn.addBack() JQMIGRATE: jQuery.clean() is deprecated
live()
has been deprecated in the latest jQuery versions but Microsoft mantains updated unobtrusive scripts as NuGet packages that overwrite the default ones:
.live()
has been replaced with the event delegation syntax of .on()
:
$('#parent').on('click', '.child', function() {
...
});
#parent
should exist when you call your selector, so if your element is top-level, use document
as the parent.