I have 7 post in the list. it has to show each 3 post when I click the Loadmore. Load More work until reach the 6 post then after it won't show the remaining one post and freeze after reach the 6 posts
By the looks of things, the value in your num_of_listing appears to be 6 - which matches the number of items that you're successfully returning.
I'm assuming the num_of_listing refers to the number of records returned? If you change this value to 10, I'd expect your "load more" function to work for 10 items.
If this is the case, then perhaps your num_of_listing should read num_of_listing: stop instead of num_of_listing: skip - since stop appears to get the total number of items whereas skip does not.
Hi, sorry for bringing this up when it's 2 years old! Found this and you helped with a blog I was working on. So found your issue and a better solution to your woes. Hopefully it helps someone else in the future too.
Setting num_of_listing: stop isn't a solution, since that just means you load all remaining articles rather than load the next 6. Not ideal!
The solution is using event delegation instead because you are rewriting the HTML on every click and the bindings are being lost. This is why we don't even hit the debugger on clicking Load More the second time. By making use of event delegation you are binding the event for present elements in the DOM and future ones that will be appended to the DOM such as those ones resulting from your AJAX calls.
Change: $(".load-more").click(function () {
To: $(document).on("click", ".load-more", function() {
I'm using this in Umbraco 8.13.0.
My full script changes very little but looks like so:
<script>
var Skip = @Skip;
var Count = Skip;
$(document).on("click", ".load-more", function() {
debugger;
Skip = Skip + Count;
$.ajax({
url: '@Model.Url()',
Type: 'get',
data: {
num_of_listing: Skip,
},
success: function (html) {
var div = $('.listing .container', $(html));
$('.listing').html(div);
}
});
});
</script>
Load More issue
I have 7 post in the list. it has to show each 3 post when I click the Loadmore. Load More work until reach the 6 post then after it won't show the remaining one post and freeze after reach the 6 posts
By the looks of things, the value in your
num_of_listing
appears to be6
- which matches the number of items that you're successfully returning.I'm assuming the
num_of_listing
refers to the number of records returned? If you change this value to 10, I'd expect your "load more" function to work for 10 items.If this is the case, then perhaps your
num_of_listing
should readnum_of_listing: stop
instead ofnum_of_listing: skip
- since stop appears to get the total number of items whereas skip does not.Hopefully this helps!
Hi, sorry for bringing this up when it's 2 years old! Found this and you helped with a blog I was working on. So found your issue and a better solution to your woes. Hopefully it helps someone else in the future too.
Setting
num_of_listing: stop
isn't a solution, since that just means you load all remaining articles rather than load the next 6. Not ideal!The solution is using event delegation instead because you are rewriting the HTML on every click and the bindings are being lost. This is why we don't even hit the debugger on clicking Load More the second time. By making use of event delegation you are binding the event for present elements in the DOM and future ones that will be appended to the DOM such as those ones resulting from your AJAX calls.
Change:
$(".load-more").click(function () {
To:
$(document).on("click", ".load-more", function() {
I'm using this in Umbraco 8.13.0. My full script changes very little but looks like so:
is working on a reply...