开发者

Need to halt a Confirm window of javascript

I have been struck up in a condition where i need to halt the Confirm box. This is what I have done:

function onBeforeClientInsert(record) {
    var eventtype = parseInt(record. < %= CEO.FieldEvaluator.GetEvaluatorByDId("EVENT_TYPE_ID").GetFieldDataFieldId() % > );
    var begindate = record. < %= CEO.FieldEvaluator.GetEvaluatorByDId("BeginDate").GetFieldDataFieldId() % > ;
    var enddate = record. < %= CEO.FieldEvaluator.GetEvaluatorByDId("EndDate").GetFieldDataFieldId() % > ;

    $.ajax({
        type: "POST",
        url: "Data.aspx/CheckInsertRecord",
        data: "{EventType:'" + eventtype + "',BeginDate:'" + begindate + "'," + "EndDate:'" + enddate + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {

            if (msg.d == "No duplicate") {

            } else {
                alert(msg.d);
                eval("var data = " + msg.d + ";");

            }
            var i = 0;
            alert(i);
            alert(data[i]);
            do {
                $("#beginDate").html(data[i].BeginDate);
                $("#eventTypeID").html(data[i].EVENT_TYPE_ID);
                $("#endDate").html(data[i].EndDate);
                $("#beginlatlong").html(data[i].BeginLATLONG);
                $("#endlatlong").html(data[i].EndLATLONG);

                var modal = document.getElementById('Div1');
                modal.style.display = '';
                modal.style.position = 'fixed';
                modal.style.zIndex = '100';
                modal.style.left = '30%';
                modal.style.top = '10%';


                var screen = document.getElementById('modalScreen');
                screen.style.display = '';
                i++;
                if (confirm("Are you sure you want to continue?") == false) {
                    hide();
                    continue;
                }


            }

            while (msg.d != null);
        }
    });


    if (confirm("Are you sure you want to insert this new record ?") == false) {
        hide();
        return false;
    }
    if (Page_ClientValidate("<%= CEO.GridUtils.Global_ValidationGroupName%>")) {
        hide();
        SetPostBackCause('INSERT');
        return true;
    }
    return false;
}

So,the problem has been that

if (confirm("Are you sure you want to insert this new record ?") == false) {
    hide();
    return false;
}

would be run immediately after the confirm box

if(confirm("Are you sure you want to continue?")==false){
    hide();
    continue;
}

But i want it to be halted until the user clic开发者_JAVA技巧ks something on the first confirm box. Can u please let me know how to do this? Also Can u let me know any other way to do this, if I'm approaching it in wrong way?


Ajax is asynchronous.

You need to move all dependent code into the success callback.

success: function (msg) {
    // snip ...
    
    if (confirm("Are you sure you want to insert this new record ?") == false) {
        hide();
    }
    if (Page_ClientValidate("<%= CEO.GridUtils.Global_ValidationGroupName%>")) {
        hide();
        SetPostBackCause('INSERT');
    }
}

You could use async: false to make the request sychronous but I do not recommend this.


You need to place all of this:

if (confirm("Are you sure you want to insert this new record ?") == false) {
        hide();
        return false;
    }
    if (Page_ClientValidate("<%= CEO.GridUtils.Global_ValidationGroupName%>")) {
        hide();
        SetPostBackCause('INSERT');
        return true;
    }

within your AJAX callback if you want it to run after the first dialog. Currently, you set the callback, and then call the code above. If your internet connection was really slow, the first dialog you are seeing could theoretically come after the second you are seeing.


Have you considered the async: false option to $.ajax?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜