如何停止新的Ajax调用如果成功后请求响应变空白?

时间:2018-10-19 18:03:33

标签: jquery ajax

我有下面的jQuery ajax代码,并在页面滚动时调用ajax请求。现在,如果响应为空,我想停止发送新的Ajax请求。我不想执行Ajax代码,这有可能吗?

var eventPage = 2;

$(window).scroll(function() {
    if ($(window).scrollTop() == $(document).height() - $(window).height()) {
        $.ajax({
            url: ajaxUrl,
            type: 'post',
            data: {
                action: 'load_events_by_ajax',
                page: eventPage,
                security: '<?php echo wp_create_nonce("load_more_events"); ?>'
            },
            beforeSend: function() {
                $('body').loading({
                    stoppable: true,
                    theme: 'dark'
                });
            },
            success: function(response) {
                $('body').loading('stop');
                $('.EventThumbRow').append(response);
                eventPage++;
            },
            error: function(xhr) {
                $('body').loading('stop');
            }
        });
    }
});

1 个答案:

答案 0 :(得分:0)

使用布尔值 flag

                          <?php
                            $term_fee = $this->db->get_where('fees' , array(
                              'student_id' => $row['student_code'], 'term' => $running_term,
                              'year' => $running_year ))->row()->fees;
                            echo $term_fee;
                              ?>