jConfirm 警报 - jQuery 插件
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;
}
});
}
});
}
}
});
});
});
我缺少什么?
Am jConfirm for user confirmation.
My first jConfirm doesnt stop for user action and just passes to next.
My Code:
$(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;
}
});
}
});
}
}
});
});
});
What am i missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否是全部,但这部分:
可能没有达到您想要的效果。它正在退出
function(ans) { ... }
函数,而您可能想退出整个处理程序,即$("#UpdateJobHandler").click(function () { ... }
。如果是这样,您需要执行类似于下面的操作 - 即在 return 之后将整个内容放入function(ans) { ... }
中可能最好分成更小的函数:
您可以对所有
success
函数执行类似的操作,您可以重写
Instances
检查。像这样:重要 - 重命名方法(
afterContinue
,afterInstances
,...)以具有对将来阅读本文的人有用的名称。Not sure if this is all, but this part:
probably doesn't do what you want. It is exiting the
function(ans) { ... }
function, while you probably want to exit the whole handler, i.e.$("#UpdateJobHandler").click(function () { ... }
. If so, you would need to do similar to what you do below - i.e. put the whole thing infunction(ans) { ... }
, after the return. Probably best to separate into smaller functions.EDIT: Something along these lines:
You can do similar thing for all the
success
functions.Another example, you can rewrite the
Instances
check like this:Important - rename the methods (
afterContinue
,afterInstances
, ...) to have some name that means something useful to someone reading this in the future.