$ .ajaxSetup for Ajax.BeginForm

$. ajaxSetup is used to call ajax in jquery. This works fine if we use jquery ajax.

But in MVC we use Ajax.BeginForm (). Callback handlers - OnFailure, OnSuccess, OnBegin.

Is it possible to use $ .ajaxSetup for Ajax.BeginForm ().

Refresh

For example, I used Ajax.BeginForm () in 10 places, but instead of writing an OnFailure handler for everyone, I just want to write one common OnFailure in a common place, like jquery $ .ajaxSetup. Is there any way to do this?

+5
source share
3 answers

Quote from the documentation $.ajaxSetup:

. Ajax -.ajaxStart(),.ajaxStop(),.ajaxComplete(),.ajaxError(),.ajaxSuccess(),.ajaxSend() - options $.ajaxSetup().

, , AJAX, .ajaxError(), , AJAX :

$(document).ajaxError(function () {
    console.log('oopsy');
});
+2

microsoft , ajax jquery.unobtusive-ajax.js, , . jquery, ? , , .

, , , .

jquery.unobtusive-ajax.js.

asyncRequest $.extend , , . .

:

complete: function () {
            loading.hide(duration);
            getFunction(element.getAttribute("data-ajax-complete"), ["xhr", "status"]).apply(this, arguments);
        },

:

complete: function () {
            loading.hide(duration);
            getFunction(element.getAttribute("data-ajax-complete"), ["xhr", "status"]).apply(this, arguments);
            $(document).trigger('ajaxComplete');
        },
+1

ajax:

:

@{
 AjaxOptions ajaxOpts = new AjaxOptions
 {
    LoadingElementDuration = 2,
    LoadingElementId = "someElementIdToShowLoading",
    UpdateTargetId = "ElementIdToLoadTo"
 };
}

:

@using (Ajax.BeginForm("ActionName", ajaxOpts)){}

. : http://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxoptions_properties.aspx

0

All Articles