I have implemented the load more functionality using ajax
in yii
. This is what I am doing in my script
:
$(document).ready(function() {
$(document).on('click', '.discover-more', function() {
$('.discover-more').hide();
$('.loading').show();
var lastId = $('ul#ulscroller li:last').attr('id');
$.ajax({
cache: false,
type: 'POST',
url: '<?php echo $host . $url . '/index.php?r=site/LoadMore&lastid=' ?>' + lastId,
success: function(data) {
$('#ulscroller').append(data);
$('.discover-more').show();
$('.loading').hide();
if (data.length() == 0) {
$('.discover-more').hide();
$('.nomore').show();
}
}
});
});
});
Now, what i have to do is to hide discover more button when there are no more images
to show. I have tried a couple of methods in the success
call back, like if(data.length() == 0)
and if(data.size() < 1)
but both do not seem to work? any ideas?
Try this,
if($.trim(data).length == 0)
hope this will work !
.length
without ()
, it is a property
and not a method
.
if (data == "") {
$('.discover-more').hide();
$('.nomore').show();
}
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.