jConfirm警报-jQuery插件 [英] jConfirm alert - jQuery plugin

查看:96
本文介绍了jConfirm警报-jQuery插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是jConfirm,用于用户确认.

Am jConfirm for user confirmation.

我的第一个jConfirm不会停止用户的操作,而只是传递到下一个.

My first jConfirm doesnt stop for user action and just passes to next.

我的代码:

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

我想念什么?

推荐答案

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

Not sure if this is all, but this part:

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

可能没有执行您想要的操作.它可能正在退出function(ans) { ... }函数,而您可能想退出整个处理程序,即$("#UpdateJobHandler").click(function () { ... }.如果是这样,您将需要执行与以下操作类似的操作,即将整个内容放在返回后的function(ans) { ... }中.最好将其分解为较小的功能.

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.

类似以下内容:

    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功能执行类似的操作.

You can do similar thing for all the success functions.

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

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

重要-将方法(afterContinueafterInstances,...)重命名为具有某些名称,这对于将来阅读此内容的人来说是有用的.

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

这篇关于jConfirm警报-jQuery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆