Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3. var offset = 9,
  4. loading = false;
  5.  
  6. $('#load-more-button').on('click', function() {
  7. var that = $(this);
  8.  
  9. if ( loading === false ) {
  10. loading = true;
  11. that.text('Hämtar...');
  12.  
  13. $.ajax({
  14. type: 'GET',
  15. url: ajax_script.ajax_url,
  16. data: {
  17. action: 'my_ajax_function',
  18. offset: offset,
  19. },
  20. success: function(data) {
  21. var result = JSON.parse(data);
  22. if(result.success === true) {
  23.  
  24. // Add new posts to the DOM
  25. $('#container').append(result.data);
  26.  
  27. offset+= 9;
  28. loading = false;
  29. if(ajax_script.post_count <= offset) {
  30. that.remove();
  31. } else {
  32. that.text('Ladda fler');
  33. }
  34. }
  35. }
  36. });
  37. }
  38. return false;
  39. });
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement