Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- var offset = 9,
- loading = false;
- $('#load-more-button').on('click', function() {
- var that = $(this);
- if ( loading === false ) {
- loading = true;
- that.text('Hämtar...');
- $.ajax({
- type: 'GET',
- url: ajax_script.ajax_url,
- data: {
- action: 'my_ajax_function',
- offset: offset,
- },
- success: function(data) {
- var result = JSON.parse(data);
- if(result.success === true) {
- // Add new posts to the DOM
- $('#container').append(result.data);
- offset+= 9;
- loading = false;
- if(ajax_script.post_count <= offset) {
- that.remove();
- } else {
- that.text('Ladda fler');
- }
- }
- }
- });
- }
- return false;
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement