Unobtrusive Ajax stopped working after update jQuery to 1.9.0

后端 未结 8 1492
灰色年华
灰色年华 2020-11-28 09:42

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)

相关标签:
8条回答
  • 2020-11-28 10:11

    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.

    0 讨论(0)
  • 2020-11-28 10:12

    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
    
    0 讨论(0)
  • 2020-11-28 10:15

    .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.

    0 讨论(0)
  • 2020-11-28 10:20

    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"));
    
    0 讨论(0)
  • 2020-11-28 10:22

    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.

    0 讨论(0)
  • 2020-11-28 10:23

    Just update your Scripts

    1. Download latest Jquery, (I used jquery-1.11.0 though)

    2. Download latest Microsoft.jQuery.Unobtrusive.Ajax from from Microsoft official

    From here:

    https://github.com/aspnet/jquery-ajax-unobtrusive

    3. Do hard refresh or Clear your browser cache and check your page again.

    Hope helps someone.

    0 讨论(0)
提交回复
热议问题