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:

我點擊F5從VS.NET進入調試模式運行,進入登錄頁面,得到如下內容:

Error Microsoft JScript

Found this StackOverflow answer: https://stackoverflow.com/a/14512797 and made the 4 changes to ~\Scripts\jquery.unobtrusive-ajax.js.

找到這個StackOverflow的答案:https://stackoverflow.com/a/14512797,並對~\腳本\ 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.

還嘗試了構建->清潔解決方案,構建->重建解決方案,然后按F5再次運行在調試模式。

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

如果有人曾經有過這樣的經歷,有什么見解,我將非常感激。提前謝謝你。

2 个解决方案

#1


17  

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.

嘗試升級您的NuGet包以獲得最新版本。

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+中的更改不兼容的問題是一個很好的建議。

#2


10  

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.

如果需要支持已刪除的特性,還需要添加包含已刪除特性的jQuery遷移文件。

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

加入類似於以下的參考資料,應包括所有你需要的功能:

<script src="http://code.jquery.com/jquery-migrate-1.1.1.js"></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博客文章。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/03/12/729fec3e5d93fa631d197962ec05dd1.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com