关闭后jquery ajax发布

时间:2017-04-26 08:45:41

标签: javascript jquery ajax

我有data-id我希望在我的模态隐藏/关闭后发布数据ID我该怎么做?

$(function() {
  var popup = $('#AniPopup');
  var time = $(".will-close strong");
  var closeSeconds = $("#AniPopup").attr("data-close");
  var openSeconds = $("#AniPopup").attr("data-open");
  var dataSrc = $("#AniPopup").attr("data-src");
  var dataId = $("#AniPopup").attr("data-id");
  

  setTimeout(function(e) {
    
    popup.modal('show');
    time.html(closeSeconds);
    
    setInterval(function(){
      time.html(closeSeconds);
      closeSeconds--;
      
      if(closeSeconds < 0){
        popup.modal('hide');
      }
      
    }, 1000)
    
  }, openSeconds * 1000);
  
    $.ajax({
    url: dataSrc,
    dataType: "html",
    success: function(data) {
      $(".modal-body").html(data);
    }
  });
  
  
});
<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="10" data-open="2" data-src="http://www.anitur.com.tr/popup/test-6-text" data-id="69">
  <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">
        this content loaded by ajax
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal">Kapat</button>
        <span class="will-close">will be closed after : <strong>n</strong> seconds</span>
      </div>
    </div>
  </div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

1 个答案:

答案 0 :(得分:1)

使用bootstrap模式的标准事件hidden.bs.modal

$("#AniPopup").on('hidden.bs.modal', function () {
    // do your staff here
});