Unobtrusive Ajax stopped working after update jQuery to 1.9.1

چند وقت پیش سعی کردم که یکی از پروژه ها رو از  MVC3 به MVC4 ارتقاء بدم. jQuery را هم به نسخه 1.9.1 ارتقاء دادم اما با خطای زیر مواجه شدم:

Error when entering login page:
Unhandled exception at line 115, column 5 in http://localhost:63180/Scripts/jquery.unobtrusive-ajax.js
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'live'

البته من متوجه این خطا نشده بودم، چون ازFirefox به عنوان مرورگر پیشفرض استفاده میکردم. ولی وقتی که  Firebug رو فعال کردم، کنسول پیغام زیر رو نشونم داد:

Type Error: a(...).live is not a function
این بود که با IE برنامه رو تست کردم و خطای اول رو گرفتم.

تابع live در نسخه 1.9.1 حذف شده و نمیشه دیگه از اون استفاده کرد. سایت jQuery  درباره این تابع و تابع جایگزین اون یعنی تابع on اینطور گفته:

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().
This method provides a means to attach delegated event handlers to the document element of a page, which simplifies the use of event handlers when content is dynamically added to a page. See the discussion of direct versus delegated events in the .on() method for more information. 

البته باید بگم که من فقط jQuery  رو به نسخه 1.9.1 ارتقاء داده بودم و jquery.unobtrusive-ajax رو هنوز ارتقاء نداده بودم. :)

برای حل این مشکل هم یا باید تمامی liveها رو به on تغییر میدادم و یا jquery.unobtrusive-ajax را هم ارتقاء میدادم. خوب بهترین راه حل همون آپدیت jquery.unobtrusive-ajax با nuget بود که منو از شر این خطا راحت کرد.

\.Chehre

جستجو