Adamhumbug Posted August 12, 2020 Share Posted August 12, 2020 Hi All, I have a function that pulls data in php form my db and uses a limit and an offset. This is currently called like this <?=getAllNews(0,1)?> with 0 being the offset and 1 being the limit. The line after this is a button triggering ajax <div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger' data-limit='1' data-offset='1'>-- Load More News --</div> and the ajax $('.loadMoreNewsTrigger').click(function(){ var offset = $(this).data('offset'); var limit = $(this).data('limit'); $.ajax({ type: 'post', data: {"ajax" : 'one', "offset" : offset, "limit" : limit}, success: function(resp){ offset = offset + 1 limit = limit + 1 $('.moreNews').append(resp + "<div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger' data-limit='limit' data-offset='$offset'>-- Load More News --</div>") } }) }); I am trying to increment the data values before appending the new button to the end but im getting tangled up. help is always appreciated Quote Link to comment Share on other sites More sharing options...
Solution Adamhumbug Posted August 12, 2020 Author Solution Share Posted August 12, 2020 i went this route in the end and didnt bother with data attributes. function getMoreNews(limit, offset){ $.ajax({ type: 'post', data: {"ajax" : 'one', "offset" : offset, "limit" : limit}, success: function(resp){ offset = offset + 1 limit = limit + 1 $('.moreNews').append(resp + "<div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger mb-3' onclick='getMoreNews(1,"+offset+");' data-limit='1' data-offset="+offset+">-- Load More News --</div>") } }) }; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.