Friday, August 2, 2013

ASP.Net Razor: jquery uncaught typeerror object has no method 'live'

This can happen if you'r using  jquery.unobtrusive-ajax with jQuery 1.9+.

jquery.unobtrusive-ajax uses old api methods that had the time to become deprecated and get entirely removed. As of this writing, JQuery is now 1.10.2 and jquery.unobtrusive-ajax still uses some removed methods.

My fix was pretty simple. Get https://github.com/jquery/jquery-migrate and include it after the jquery include line. The old methods (like live()) are now back.

<script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-migrate-1.2.1.min.js")" type="text/javascript"></script>

This should be only a temporary fix until MS gets in the real world and start using up to date APIs ;)

Hope this helps!

No comments: