JCONFIRM警报-JQuery插件
-
09-10-2019 - |
题
Am Jconfirm用于用户确认。
我的第一个JCONFIRM并没有停止用于用户操作,而只是传递到下一步。
我的代码:
$(function () {
$("#UpdateJobHandler").click(function () {
var JobHander = getJobHandler();
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (!ans)
return;
});
}
var json = $.toJSON(JobHander);
$.ajax({
url: '../Metadata/JobHandlerUpdate',
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
var message = data.Message;
var alertM = data.MessageType;
if (alertM == 'Error') {
$("#resultMessage").html(message);
}
if (alertM == 'Success') {
$("#resultMessage").empty();
alert(alertM + '-' + message);
action = "JobHandler";
controller = "MetaData";
loc = "../" + controller + "/" + action;
window.location = loc;
}
if (alertM == "Instances") {
jConfirm(message, 'Instances Confirmation?', function (answer) {
if (!answer)
return;
else {
var JobHandlerNew = getJobHandler();
JobHandlerNew.FinalUpdate = "Yes";
var json = $.toJSON(JobHandlerNew);
$.ajax({
url: '../Metadata/JobHandlerUpdate',
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
var message = data.Message;
$("#resultMessage").empty();
alert(alertM + '-' + message);
action = "JobHandler";
controller = "MetaData";
loc = "../" + controller + "/" + action;
window.location = loc;
}
});
}
});
}
}
});
});
});
我想念什么?
解决方案
不确定这是否全部,但是这部分:
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (!ans)
return;
});
}
可能没有做你想要的。它正在退出 function(ans) { ... }
功能,虽然您可能想退出整个处理程序,即 $("#UpdateJobHandler").click(function () { ... }
. 。如果是这样,您需要做与下面所做的类似的事情 - 即将整个事情放入 function(ans) { ... }
, ,返回之后。最好分为较小的功能。
编辑:沿着这些行:
function afterContinue() {
var json = $.toJSON(JobHander);
$.ajax({
// ... all other lines here ...
});
}
if (JobHander.MaxInstances == 0) {
jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (ans) {
afterContinue();
}
});
}
您可以为所有人做类似的事情 success
功能。
另一个例子,您可以重写 Instances
这样检查:
function afterInstances() {
var JobHandlerNew = getJobHandler();
JobHandlerNew.FinalUpdate = "Yes";
// ... and everything under else branch ...
}
if (alertM == "Instances") {
jConfirm(message, 'Instances Confirmation?', function (answer) {
if (answer) {
afterInstances();
}
});
}
重要 - 重命名方法(afterContinue
, afterInstances
, ,...)有一些名称,这对未来阅读此书的人有用。
不隶属于 StackOverflow