Posted By

mr_wza on 07/16/13


Tagged

ajax wordpress jquery


Versions (?)

Wordpress AJAX jQuery script


 / Published in: jQuery
 

  1. // ajaxLoop.js
  2. jQuery(function($){
  3.  
  4. function reQuery(){
  5.  
  6. var thisDomain = 'http://davocom'; // no end slash
  7.  
  8. var page = 1;
  9. var loading = true;
  10. var $window = $(window);
  11. var $content = $('.ajaxContent');
  12. var load_posts = function(){
  13. $.ajax({
  14. type : 'GET',
  15. data : {numPosts : 6, pageNumber: page},
  16. dataType : 'html',
  17. url : thisDomain+"/wp-content/themes/.../ajaxLoop.php",
  18. beforeSend : function(){
  19. if(page != 1){
  20. $content.append('<div id="temp_load" style="text-align:center">\
  21. <img src="../images/ajax-loader.gif" />\
  22. </div>');
  23. }
  24. },
  25. success : function(data){
  26. $data = $(data);
  27. if($data.length){
  28. $data.hide();
  29. $content.html($data);
  30. $data.fadeIn(500, function(){
  31. $("#temp_load").remove();
  32. loading = false;
  33. });
  34. $('ul.categories li a').removeClass('strong');
  35. $('ul.categories li.category-'+arg+' a').addClass('strong');
  36. } else {
  37. $("#temp_load").remove();
  38. }
  39. },
  40. error : function(jqXHR, textStatus, errorThrown) {
  41. $("#temp_load").remove();
  42. alert(jqXHR + " :: " + textStatus + " :: " + errorThrown);
  43. }
  44. });
  45. }
  46. $window.scroll(function() {
  47. var content_offset = $content.offset();
  48. //console.log(content_offset.top);
  49. if(!loading && ($window.scrollTop() +
  50. $window.height()) > ($content.scrollTop() +
  51. $content.height() + content_offset.top)) {
  52. loading = true;
  53. page++;
  54. load_posts();
  55. }
  56. });
  57. load_posts();
  58.  
  59. }
  60.  
  61. });

Report this snippet  

You need to login to post a comment.