2017-03-15 61 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