i want to load wordpress posts using ajax on window scroll, it must be similar to facebook loading posts,But i am in stuck with some issue, I have used the code that is loading the posts on window scroll, when i scroll window it shows the posts, but rather showing one by one posts it shows the all posts on single window scroller. Here is the code which i use for this purpose.
Can any one help me to figure out the issue.
Thanks in advance
<script type="text/javascript">
jQuery(document).ready(function ($) {
$(window).scroll(function () {
var ajaxURL = '<?php echo get_admin_url(); ?>admin-ajax.php';
var post_id = $('.ajaxclick').attr('id');
$.ajax({
url: ajaxURL,
type: 'POST',
cache:false,
beforeSend: function() {
$("#loading_animation").hide();
$("#ajaxloader").show();
},
complete: function() {
$("#loading_animation").show();
$("#ajaxloader").hide();
},
data: {
action: 'load_content',
post_id: post_id,
},
success: function(response){
// var i = setInterval( function() {
// jQuery("#loading_animation").html(response); //Whatever the php page to do the query against here
// }, 5000 //timeout in miliseconds
// );
jQuery("#loading_animation").html(response);
return false;
}
});
});
});
</script>