2014-02-19 69 views
2

HTML引導Bootbox點擊保存按鈕

<a href="#modal-2" role="button" class="btn" data-toggle="modal">Modal with animation</a> 

<div id="modal-2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
       <h3 id="myModalLabel">Modal header</h3> 
      </div> 
      <div class="modal-body"> 
       <p>One fine body…</p> 
      </div> 
      <div class="modal-footer"> 
       <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 
       <button class="btn btn-primary" id="book" >Save changes</button> 
      </div> 
     </div> 

我已經使用floowing JS之後,去除彈出,但沒有結果

$('#book').click(function(e) { 
     $.ajax({ 
      url: base_url+"admin/login/", 
      type: "get", 
      data: {Name:name, Mobile:mobile}, 
      success: function(strData){ 
       //$('.modal, .modal-backdrop').hide(); 
       $("#modal-2").modal('hide'); 

      }, 
      error: function(){ 
       $('#report').text('Sorry, Please try again').css('color', 'red'); 
      } 
     }); 
    }); 

在這裏,我想打電話給在回調AJAX功能後,點擊保存按鈕。 然後在阿賈克斯成功後,我想關閉bootbox彈出

+0

您的問題是什麼? – xivo

+0

我無法關閉彈出窗口 – user123456789

+0

在jsfiddle中運行代碼時,我沒有關閉彈出窗口的問題。你有一個問題,你添加「隱藏」到你的模態班,這將阻止你的模態打開。可能還有其他問題導致問題。 – xivo

回答

1

如果你使用BootBox,你可以做這樣的事情:

bootbox.dialog({ 
     message: "Your Message Here - You can pass in an HTML string", 
     title: "Your Title", 
     onEscape: function() { 
      bootbox.hideAll(); 
     }, 
     buttons: { 
      danger: { 
       label: "Cancel", 
       className: "btn default", 
       callback: function() { 
        bootbox.hideAll(); 
       } 
      }, 
      success: { 
       label: "Add", 
       className: "btn blue", 
       callback: function() { 

     //Add functionality here 

     // Then close the model using 
     bootbox.hideAll(); 

       } 
      } 
     } 
    }); 
+0

它不起作用,它仍然沒有等到ajax完成。點擊按鈕後,它總是關閉窗口。 –

0

AJAX的定義裏面,你應該使用參數

async : false 

您可能需要在模式窗口的主體內使用自定義按鈕,而不是從bootbox中獲得這些按鈕