2016-06-09 52 views
-1

我有一個登錄href鏈接,切換模式並在iframe中加載頁面。成功登錄後,模式不會關閉。一直在這裏搜索,大部分的答案是添加在線ajax成功關閉bootstrap模式

$('#myModal').modal('hide'); 

試過,但它沒有奏效。我的代碼中是否存在任何衝突?

HTML

<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
<div class="modal-dialog" style="max-width:400px;max-height:400px;width:94%;height:75%;float:right;margin:50px 12px 0 0"> 
    <div class="modal-content" style="position:relative;width:100%;height:100%;"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
     <span style="color:black;font-weight:900;">Login</span> 
     </div> 
     <div class="modal-body" style="position:absolute;display:inline-block;width:100%;height:100%;"> 
     <iframe src="login.php" frameborder="0" scrolling="no" allowtransparency="true" style="width:100%;height:90%;"></iframe> 
     </div> 
    </div> 
</div> 

阿賈克斯

$.ajax({ 
    url: url, 
    type: "post", 
    data: val, 
    datatype: 'json', 
    success: function(data) { 
    if (data.status == "valid") { 
     $("input").prop('disabled', true); 
     $("#login_btn").prop('value', 'Logging in ...'); 
     $('#myModal').modal('hide'); 
    } 
    else { 
     $('#msg').html("<font color=red>" +data.message+ "</font>") 
    } 
    } 
}); 
+0

你的'data.status'包含了什麼?你成功了嗎?你到達'if(data.status =='valid')'還是落到'else'? 'FONT'標籤已被棄用:http://www.w3schools.com/tags/tag_font.asp – Justinas

+0

可能重複[編程方式關閉ajax成功啓動模式](http://stackoverflow.com/questions/36122756/programmatically- close-bootstrap-modal-on-ajax-success) – danielad

+0

data.status來自我的php json數據,它返回狀態和消息字符串,我不認爲這是問題,因爲消息已成功返回。 感謝您的亮點我會修改字體標籤:) –

回答

0

我也有類似的問題,這是推動我瘋了。結果我想出了一種瘋狂的解決方案。

我在用於創建popover的template中添加了一個類。這裏是作爲一個選項popover()函數模板:

template: '<div class="popover popover-width-control add-calendar-event"><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>', 

這裏的關鍵是增加了類add-calendar-event的。然後隱藏我使用的模式:

$(".add-calendar-event").hide();