ajax电话没有发生

时间:2015-08-10 07:11:47

标签: jquery ajax

动画完成后,我按如下所示进行ajax调用,但没有任何反应。 Ajax调用根本没有发生。什么都没有发送到处理ajax请求的php文件。我不明白错误或错过了什么。 提前致谢!!!

$('.open, .closed, .appoint').each(function (index) {

    var $control = $('#' + (firstDay + index));
    $control.animate({
        top: pos[firstDayNext + index].top,
        left: pos[firstDayNext + index].left + (($control.html() < 10) ? 5.7 : 0),
        }, (400 + (25 * index)));

}).promise().always(function(){

    $.ajax({
        type:"GET",
        url:"ajax/showingAppointmentForMonth.php",
        dataType:'JSON',
        data:"year=" + currentYear + "&month=" + currentMonthInteger + "&id=" + "<?php echo $id;?>",
        success:function(data){
            //do something with the data
        }
    });

});

1 个答案:

答案 0 :(得分:1)

因为动画不会在迭代的元素集中发生,所以不会调用promise。

而是使用.map()并返回$control元素并在该组元素上调用promise

var firstDay = '01-Aug-'

$('.open, .closed, .appoint').map(function(index) {
  var $control = $('#' + (firstDay + index));
  $control.animate({
    height: 'hide' //to demo
  }, (4000 + (25 * index)));
  return $control.get();
}).promise().always(function() {

  alert('ajax')

  //ajax here
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<span class="open">open</span>
<span class="closed">closed</span>
<span class="appoint">appoint</span>

<br />
<div id="01-Aug-0">01-Aug-1</div>
<div id="01-Aug-1">01-Aug-2</div>
<div id="01-Aug-2">01-Aug-3</div>

相关问题