Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jConfirm警报-jQuery插件_Jquery_Jquery Ui_Jquery Plugins_Jconfirm - Fatal编程技术网

jConfirm警报-jQuery插件

jConfirm警报-jQuery插件,jquery,jquery-ui,jquery-plugins,jconfirm,Jquery,Jquery Ui,Jquery Plugins,Jconfirm,Am jConfirm用于用户确认 我的第一个jConfirm没有停止用户操作,只是传递到下一个 我的代码: $(function () { $("#UpdateJobHandler").click(function () { var JobHander = getJobHandler(); if (JobHander.MaxInstances == 0) { jConfirm('Continue?', 'Cur

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;
            });
    }
可能不会做你想做的事。它正在退出
函数(ans){…}
函数,而您可能希望退出整个处理程序,即
$(“#UpdateJobHandler”)。单击(函数(){…}
。如果是这样,您需要执行与下面类似的操作-即将整个内容放入
函数(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
函数执行类似的操作

另一个例子是,您可以像这样重写
实例
检查:

            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
,…),使其具有一些名称,这对将来阅读本文的人来说是有用的。

谢谢icyrock,您可以通过将这些方法拆分为更小的函数来展示一些重新分解这些方法的示例吗。