我在 MVC2 中使用 Ajax.BeginForm 进行 ajax 调用,如下所示:
using (Ajax.BeginForm("methoname", "controller", new AjaxOptions
{
HttpMethod = "Post",
OnSuccess = "OnSuccessUserSave",
UpdateTargetId = "PopupBody"
}))
现在,我想在请求发送时显示加载并在请求完成/成功/失败时停止它。
我知道我可以使用
OnBegin = "startLoading",
OnComplete = "stopLoading",
OnFailure = "stopLoading",
OnSuccess = "stopLoading"
但是,我不想这样。
我有很多这样的要求。
所以,我想用 jQuery 制作。
一旦我编写了 jquery 脚本,它就会为每个请求触发。
我喜欢这样:
$(document).ajaxSuccess(function () {
$('#LoadingImage').modal('hide');
});
$(document).ajaxComplete(function () {
$('#LoadingImage').modal('hide');
});
$(document).ajaxSend(function () {
$('#LoadingImage').modal('show');
});
$(document).ajaxError(function () {
$('#LoadingImage').modal('hide');
});
但是,它仅适用于以下语法:
$.ajax({
type: "GET",
url: "NewUser/Testing",
dataType: "json",
// cache: false,
success: function (response) {
alert("Request Success");
},
error: function (xhr, status) {
alert('Unknown error ' + status);
}
});
而且,它不适用于 Ajax.BeginForm。
我应该怎么做它与 jquery 一起使用?
任何帮助将不胜感激。
提前致谢。