我正在寻找解决方案并来到这里。尽管达林断然否认解决方案的可能性,但他的回答实际上让我找到了解决方案。
如果您可以在捆绑包中提供jquery.unobtrusive-ajax.js文件,那么您可以继续使用该解决方案
注意:此示例使用Bootstrap 对话框
将 jquery.unobtrusive-ajax.js 中的函数替换为asyncRequest(element, options)
这个
function asyncRequest(element, options) {
var confirm = element.getAttribute("data-ajax-confirm");
if (confirm) {
BootstrapDialog.confirm({
title: 'Please Confirm!',
type: BootstrapDialog.TYPE_WARNING,
message: confirm,
draggable: true,
callback: function (result) {
if (result) {
NewMethod(element, options);
}
}
});
}
else {
NewMethod(element, options);
}
}
function NewMethod(element, options)
{
var loading, method, duration;
loading = $(element.getAttribute("data-ajax-loading"));
duration = parseInt(element.getAttribute("data-ajax-loading-duration"), 10) || 0;
$.extend(options, {
type: element.getAttribute("data-ajax-method") || undefined,
url: element.getAttribute("data-ajax-url") || undefined,
cache: !!element.getAttribute("data-ajax-cache"),
beforeSend: function (xhr) {
var result;
asyncOnBeforeSend(xhr, method);
result = getFunction(element.getAttribute("data-ajax-begin"), ["xhr"]).apply(element, arguments);
if (result !== false) {
loading.show(duration);
}
return result;
},
complete: function () {
loading.hide(duration);
getFunction(element.getAttribute("data-ajax-complete"), ["xhr", "status"]).apply(element, 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(element, arguments);
},
error: function () {
getFunction(element.getAttribute("data-ajax-failure"), ["xhr", "status", "error"]).apply(element, arguments);
}
});
options.data.push({ name: "X-Requested-With", value: "XMLHttpRequest" });
method = options.type.toUpperCase();
if (!isMethodProxySafe(method)) {
options.type = "POST";
options.data.push({ name: "X-HTTP-Method-Override", value: method });
}
$.ajax(options);
}