Created
May 29, 2013 10:35
-
-
Save danielgreen/5669399 to your computer and use it in GitHub Desktop.
This is an amended fragment of Microsoft jQuery Unobtrusive Ajax (http://nuget.org/packages/Microsoft.jQuery.Unobtrusive.Ajax). The change is to the error property, to ensure that it calls .apply() to invoke the function specified by the data-ajax-failure attribute. Previously it did not call .apply() hence the error handler specified by the pag…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.extend(options, { | |
type: element.getAttribute("data-ajax-method") || undefined, | |
url: element.getAttribute("data-ajax-url") || undefined, | |
beforeSend: function (xhr) { | |
var result; | |
asyncOnBeforeSend(xhr, method); | |
result = getFunction(element.getAttribute("data-ajax-begin"), ["xhr"]).apply(this, arguments); | |
if (result !== false) { | |
loading.show(duration); | |
} | |
return result; | |
}, | |
complete: function () { | |
loading.hide(duration); | |
getFunction(element.getAttribute("data-ajax-complete"), ["xhr", "status"]).apply(this, arguments); | |
}, | |
success: function (data, status, xhr) { | |
asyncOnSuccess(element, data, xhr.getResponseHeader("Content-Type") || "text/html"); | |
getFunction(element.getAttribute("data-ajax-success"), ["data", "status", "xhr"]).apply(this, arguments); | |
}, | |
error: function () { | |
// Ensure the error handling function is invoked using .apply() | |
getFunction(element.getAttribute("data-ajax-failure"), ["xhr", "status", "error"]).apply(this, arguments); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment