ASP。NET MVC 4:不能修改jQuery Unobtrusive Ajax。

[英]ASP.NET MVC 4: cannot modify jQuery Unobtrusive Ajax

Using ASP.NET MVC 4 and NuGet to manage packages.

使用ASP。NET MVC 4和NuGet來管理包。

After upgrading to jQuery 1.9.1 via NuGet, I began getting JavaScript errors regarding the removal of the live() function in jQuery 1.9.x.

通過NuGet升級到jQuery 1.9.1之后,我開始在jQuery 1.9.x中刪除live()函數的JavaScript錯誤。

I hit F5 to run in debugging mode from VS.NET, go to the login page, and get the following:


Error Microsoft JScript

Found this StackOverflow answer: and made the 4 changes to ~\Scripts\jquery.unobtrusive-ajax.js.

找到這個StackOverflow的答案:,並對~\腳本\ jquery.unobtrusi-ajax.js進行了4個修改。

My ~\Scripts\jquery.unobtrusive-ajax.js:

我~ \ \ jquery.unobtrusive-ajax.js腳本:

    $(document).on("click", "a[data-ajax=true]", function (evt) {
    $(document).on("click", "form[data-ajax=true] input[type=image]", function (evt) {
    $(document).on("click", "form[data-ajax=true] :submit", function (evt) {
    $(document).on("submit", "form[data-ajax=true]", function (evt) {

I also physically deleted jquery.unobtrusive-ajax.min.js and used WebGrease 1.3.0 to regenerate it from my updated ~\Scripts\jquery.unobtrusive-ajax.js.

我還刪除了jquer.unobtrusive -ajax.min。使用web潤滑脂1.3.0從我更新的~\腳本jquer.unobtrusive -ajax.js中重新生成它。

However, for some reason, my changes to not use the .live() function are not sticking. I tried stopping the IIS Express 8.0 Web Site (localhost:63798) under which VS.NET is running the MVC App.

但是,由於某些原因,我對不使用.live()函數的更改沒有被堅持。我嘗試停止IIS Express 8.0 Web站點(localhost:63798),其中VS.NET正在運行MVC應用程序。

Also tried doing a Build->Clean Solution, Build->Rebuild Solution before hitting F5 to run in debug mode again.


If anyone has experienced this before and has any insight, I would be very grateful. Thank you in advance.


2 个解决方案



The Microsoft jQuery Unobtrusive Ajax package has been fixed in version 2.0.30116.0 to fix this problem. The calls to .live() were changed to use .on().

Microsoft jQuery不引人注目的Ajax包已經在2.0.30116.0版本中修復了這個問題。對.live()的調用被更改為use .on()。

Try upgrading your NuGet package to get the latest version.


However, the suggestion to use the jQuery Migrate package is a good one to find issues in other plugins or your own code that aren't compatible with the changes in jQuery 1.9+.

但是,使用jQuery遷移包的建議對於發現其他插件或您自己的代碼中與jQuery 1.9+中的更改不兼容的問題是一個很好的建議。



live() has been removed in jQuery 1.9 along with a few other features.

live()在jQuery 1.9中已經被刪除,還有其他一些特性。

If you need to have support for removed features you need to also add the jQuery migrate file which contains the removed features.


Adding the reference similar to below should include all the features you need:


<script src=""></script>

The migrate file in debug mode will also add warnings to your console notifying you when you use any removed features. This will help you in slowly replacing them as you go along leading to eventually you being able to remove the migrate file reference, using only jQuery 1.9 and beyond.

調試模式下的遷移文件還將向您的控制台添加警告,當您使用任何已刪除的特性時通知您。這將幫助您慢慢地替換它們,直至最終您能夠使用jQuery 1.9或更高版本刪除遷移文件引用。

See the following jQuery blog posts for all the details on migrating to jQuery 1.9.

有關遷移到jQuery 1.9的所有細節,請參閱以下jQuery博客文章。



粤ICP备14056181号  © 2014-2020