jConfirm 警报 - jQuery 插件

发布于 2024-10-06 01:33:29 字数 2740 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风尘浪孓 2024-10-13 01:33:29

不确定这是否是全部,但这部分:

    if (JobHander.MaxInstances == 0) {
            jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
                if (!ans)
                    return;
            });
    }

可能没有达到您想要的效果。它正在退出 function(ans) { ... } 函数,而您可能想退出整个处理程序,即 $("#UpdateJobHandler").click(function () { ... }。如果是这样,您需要执行类似于下面的操作 - 即在 return 之后将整个内容放入 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();
                    }
                });
            }

重要 - 重命名方法(afterContinueafterInstances,...)以具有对将来阅读本文的人有用的名称。

Not sure if this is all, but this part:

    if (JobHander.MaxInstances == 0) {
            jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
                if (!ans)
                    return;
            });
    }

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 in function(ans) { ... }, after the return. Probably best to separate into smaller functions.

EDIT: Something along these lines:

    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();
                }
            });
    }

You can do similar thing for all the success functions.

Another example, you can rewrite the Instances check like this:

            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();
                    }
                });
            }

Important - rename the methods (afterContinue, afterInstances, ...) to have some name that means something useful to someone reading this in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文