我已经使用 ajax
实现了加载更多功能在yii
。这就是我在 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();
}
}
});
});
});
现在,我要做的就是在没有更多 images
时隐藏“发现更多”按钮以显示。我在 success
中尝试了几种方法回电,例如 if(data.length() == 0)
和if(data.size() < 1)
但两者似乎都不起作用?有什么想法吗?
最佳答案
试试这个,
if($.trim(data).length == 0)
希望这会起作用!
关于javascript - ajax 在没有更多数据时隐藏加载更多按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34589875/