2014-10-08 86 views
0

正如你所看到的,在触发ajax post之前我有yes/no确认对话框。ajax成功后关闭jquery确认对话框

成功后,确认对话框仍然可见。

我失踪了什么?

function AbandonOrder() { 
    $('<div></div>').appendTo('body') 
      .html('<div><strong>Abandon order? <br/> You will be unable to edit this order in the future.</strong></div>') 
      .dialog({ 
       modal: true, title: 'Abandon order', zIndex: 10000, autoOpen: true, 
       width: 400, resizable: false, 
       buttons: { 
        Yes: function() { 
         jQuery.ajax({ 
          url: 'some_URL', 
          type: "POST", 
          dataType: "JSON", 
          success: function (data) { 
           if (data == 'OKAY') { 
            tosomething(); 
            $('#dlgCard').dialog("close"); 
           } 
           else { 
            $("#divMsg").html("<ul><li>This order cannot be edited.</li></ul>") 
            $('#dlgMsg').dialog('open'); 
           } 
            //$(this).dialog("close"); 
            $(this).remove(); 
          } 
         }); 
        }, 
        No: function() { $(this).dialog("close"); } 
       }, 
       close: function (event, ui) { $(this).remove(); } 
      }); 
    $('.ui-button-text').css({ fontSize: 12 }); 
    $('.ui-dialog-title').css({ fontSize: 12 }); 
} 

我tryed与

$(this).dialog("close"); 

$(this).remove(); 

但确认仍然可见。

+0

有你试图改变CSS能见度隐藏? – 2014-10-08 12:50:58

+0

@MrCoder我想通过jquery关闭对话框。我没有尝试。 – dllhell 2014-10-08 12:52:47

+0

[此网站](http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/)可能会使您受益。加上配置看起来也很干净! – 2014-10-08 12:55:40

回答

0

这是this的范围 - 在AJAX请求中,this将绑定到请求对象而不是您的DOM元素。为了清楚起见,我撕了在一开始:

var elem = $("<div></div>"); 
elem.html(...); 
在要关闭它的所有点

则:

elem.dialog("close"); 

您也可以通过一个context选项AJAX请求,将结合this到指定的对象:

// Assuming we have var elem as above 
jQuery.ajax({context: elem[0], success: function() { $(this).dialog('close') }}); 

但是,这不仅仅是在开始提取变量了明确的要少得多。

0

我认为你应该使用

$("#dlgMsg").dialog("close"); 

正如你所dlgMsg对话框打开,但你试图关闭对话框卡$('#dlgCard').dialog("close");