2017-03-15 100 views
0

我有自舉模式please click to see demo和我的模式已經自動打開並自動關閉,我需要一件事是ajax內容,我想它可以與負載函數我發現了一些功能,但我couldn'因爲我不希望做T將它應用於負載通過點擊鏈接我有我的模式開Ajax負載與自舉模式

我有兩個屬性data-opendata-close打開和關閉自動模式我

$(function(){ 
 
    setTimeout(function(e){ 
 
    $('#AniPopup').modal('show'); 
 
    }, parseInt($('#AniPopup').attr('data-open')) * 1000); 
 
    setTimeout(function(e){ 
 
    $('#AniPopup').modal('hide'); 
 
    }, parseInt($('#AniPopup').attr('data-close')) * 1000); 
 
    
 
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 

 

 

 
<div class="modal fade" id="AniPopup" tabindex="-1" role="dialog" aria-labelledby="AniPopupLabel" aria-hidden="true" data-close="1000" data-open="2" data-src="https://www.youtube.com"> 
 
    <div class="modal-dialog"> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
     <h4 class="modal-title" id="memberModalLabel">Popup Header</h4> 
 
     </div> 
 
     <div class="modal-body"></div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-primary" data-dismiss="modal">Kapat</button> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div> 
 

 

 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
後自動加載

回答

1

你打電話叫你的Ajax請求到這個代碼..

$(function(){ 
      setTimeout(function(e){ 
       $.ajax({ 
        type: 'GET', 
        data: {}, 
        url: [Server URL], 
        success: function(response){ 
         // do anything with response you want 
         $('#AniPopup').modal('show'); 
         hidePopUp(); // you have to initiate hidepopup to ensure you timeout is after ajax complete not before as ajax are async call. 
        } 
       }) 
      }, parseInt($('#AniPopup').attr('data-open')) * 1000); 

      function hidePopUp(){ 
       setTimeout(function(e){ 
       $('#AniPopup').modal('hide'); 
       }, parseInt($('#AniPopup').attr('data-close')) * 1000); 
      } 
     }); 
+0

沒錯這就是好,但不工作我設置網絡地址到網址可能是這樣,爲什麼不工作......並有什麼辦法從屬性獲取網址?像'data-open'或'data-close' –

+0

它必須調用'.modal-body'我的ajax內容 –

+0

網址不是你的網址,你需要從你的服務器得到響應JSON。 – user7417866

1

引導爲您提供這些選項

$('#myModal').on('hidden.bs.modal', function (e) { 
    // do something...probably make an ajax call and get data 
}) 

$('#myModal').on('shown.bs.modal', function (e) { 
    // do something... 
}) 

http://getbootstrap.com/javascript/#modals