简体   繁体   中英

Not able to check the empty data returned from view

I am working on Infinite scrolling.

Here is the code in js

$('.workspace-activity .modal-body').scroll(function() {
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) 
    {
           loadResults(base + 'co8/workspace/activityLogPagination');
    }
 });


function loadResults(url) {
start = parseInt($('.modal-body .acti-count').length);
var id = $(".single-workspace").attr("data-id");
$.ajax({
    url: url,
    type: "POST",
    data: "start=" + start + "&limit=10&type=workspace&id=" + id,
    success: function(data) {
        if (!data) {
            noData = '<h5 class="no-data">No more data</h5>';
            $('.workspace-activity .modal-body').append(noData);
        } else {
            $('.workspace-activity .modal-body').append(data);
        }
    }
});
};

The problem is with !data .

The data returned is empty but the if statement executes the else statement, Is the condition checking correct?

The problem might exists with the blank spaces

!$.trim(data) will remove the blank spaces

The updated javascript function is

function loadResults(url) {
start = parseInt($('.modal-body .acti-count').length);
var id = $(".single-workspace").attr("data-id");
$.ajax({
    url: url,
    type: "POST",
    data: "start=" + start + "&limit=10&type=workspace&id=" + id,
    success: function(data) {
        if (!$.trim(data)) {
            noData = '<h5 class="no-data">No more data</h5>';
            $('.workspace-activity .modal-body').append(noData);
        } else {
            $('.workspace-activity .modal-body').append(data);
        }
    }
});
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM