ross dickinson: web and desktop software developer

Microsoft's jquery.unobtrusive-ajax library doesn't work with errors

by Ross on December 23, 2011 at 8:57 AM under

If you're using Microsoft's unobtrusive ajax library with your MVC3 project, you might come across a problem if you're trying to add an error handler to one of your Ajax.BeginForm or Ajax.ActionLink calls.

The problem lies in the library's handling of the data-ajax-failure attribute that gets added to an ajax form/link. Basically, the library just doesn't execute the method after finding it. The problem line of code is line 98 of jquery.unobtrusive-ajax.js:

$.extend(options, {
    // other handler code removed
    error: getFunction(element.getAttribute("data-ajax-failure"), ["xhr", "status", "error"])
});

To fix this, you need to change line 98 to this:

 

$.extend(options, {
    error: function() {
        getFunction(element.getAttribute("data-ajax-failure"), ["xhr", "status", "error"]).apply(this, arguments);
    }
});

Add comment

biuquote
  • Comment
  • Preview
Loading

About the author

rossisdead is a 26 year old web and desktop software developer from New Jersey. He has two cats and likes long walks on the beach.

On Stackoverflow

On Stackoverflow Careers

On Codeplex

On Github