Unobtrusive Ajax stopped working after update jQue

2020-01-25 07:15发布

I have just updated jQuery & jQuery UI to: jquery-1.9.0.min.js and jquery-ui-1.9.2.min.js

And... all my unobtrusive Ajax calls (Ajax.ActionLink, Ajax.BeginForm) stopped working properly - they open results in a new page instead of updating the existing div.

And I get this javascript error in Firebug when my page loads:

enter image description here

Code hasn't changed of course, just updated the jQuery scripts using Nuget.

Anyone experienced the same problem ??

8条回答
在下西门庆
2楼-- · 2020-01-25 07:15

The easiest way to fix problems with the breaking changes in jQuery(in my opinion) is to install the jQuery.Migrate package that enables you to use deprecated function calls that were removed in version 1.9.0 onwards. At least until the unobtrusive ajax plugin is updated by Microsoft.

Also, it appears that the nightly build of the unobtrusive ajax plugin have updated the api calls. I haven't tested it yet but you may find out how to acquire it in the asp.net codeplex page.

UPDATE: The Unobtrusive Ajax and Validation Nuget packages were updated so the jQuery.Migrate package isn't needed anymore.

查看更多
三岁会撩人
3楼-- · 2020-01-25 07:15

Also need to do these fixes :

Update jQuery.Validation plugin (to fix this problem)

https://nuget.org/packages/jQuery.Validation/1.11.0    (first available on nuget 2/4/13)

Also make these changes to the jquery.unobtrusive-ajax.js file (see here for Connect issue)

Line 43: replace = container.attr("data-valmsg-replace") && $.parseJSON(container.attr("data-valmsg-replace")) !== false;

Line 73: replace = container.attr("data-valmsg-replace") && $.parseJSON(container.attr("data-valmsg-replace"));
查看更多
beautiful°
4楼-- · 2020-01-25 07:15

Replace

.live(function)

With

.on(eventType, selector, function)

https://stackoverflow.com/a/14354091/358906

查看更多
萌系小妹纸
5楼-- · 2020-01-25 07:19

Update: This issue has been fixed in the latest NuGet package. I've posted another answer to reflect this. https://stackoverflow.com/a/15539422/714309


In jquery.unobtrusive-ajax.js, find and replace these four lines:

  1. $("a[data-ajax=true]").live("click", function (evt) {

    $(document).on("click", "a[data-ajax=true]", function (evt) {

  2. $("form[data-ajax=true] input[type=image]").live("click", function (evt) {

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

  3. $("form[data-ajax=true] :submit").live("click", function (evt) {

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

  4. $("form[data-ajax=true]").live("submit", function (evt) {

    $(document).on("submit", "form[data-ajax=true]", function (evt) {

You can also generate a new jquery.unobtrusive-ajax.min.js using WebGrease. From the Command Prompt, change to your solution folder and enter this command (assuming your project folder is called Web):

packages\WebGrease.1.3.0\tools\WG.exe -m -in:Web\Scripts\jquery.unobtrusive-ajax.js -out:Web\Scripts\jquery.unobtrusive-ajax.min.js
查看更多
劫难
6楼-- · 2020-01-25 07:20

.live() has been deprecated since 1.7 and was officially removed in jQuery 1.9. Use .on() instead as it is the preferred method of doing the same thing.

查看更多
时光不老,我们不散
7楼-- · 2020-01-25 07:24

Update the Microsoft jQuery Unobtrusive Ajax NuGet package to the latest version.

In Visual Studio, from the Tools menu, select Library Package Manager and then click Package Manager Console. At the prompt, type:

Update-Package Microsoft.jQuery.Unobtrusive.Ajax

This issue was fixed in Microsoft jQuery Unobtrusive Ajax 2.0.30116.0 (Monday, February 18, 2013), which replaced the calls to the .live() method (deprecated in jQuery 1.7 and removed from jQuery 1.9) with the recommended .on() method.

查看更多
登录 后发表回答