2011-06-27 45 views
0

我已经在需要暂停确认框的情况下被触发。这是我做了什么:需要暂停javascript的确认窗口

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

所以,这个问题一直是

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

将确认框中

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

后立即运行,但我想它被叫停直到用户点击第一个确认框上的某个东西。你可以让我知道如何做到这一点?如果我以错误的方式接近它,你还可以让我知道任何其他方式来做到这一点吗?

+0

一旦你得到这个代码的工作,**请**发布在[代码评论](http://codereview.stackexchange.com)的清理建议。 –

+0

@Matt:当然我会发布它 – Sayamima

回答

2

Ajax是异步的。

您需要将全部相关代码移入success回调。

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

可能使用async: false发出请求采用同步,但我推荐这个。如果你想让它的第一个对话框后运行

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

您的AJAX回调中:

+0

我试过这个......但第二个确认框没有被调用 – Sayamima

1

您需要将所有这一切。目前,您设置回调,然后调用上面的代码。如果您的互联网连接速度很慢,您看到的第一个对话框理论上会在您看到的第二个对话框后出现。

+0

我试图保持它在成功功能,但第二个符合框不会显示出来。 – Sayamima

0

你有没有考虑到$ .ajax的async:false选项?

+0

否我会尝试的 – Sayamima