Ajax requests give 0 response / infinite scroll
-
Hi,
I’d like to implement a very customized infinite scroll. But that comes later, cause i’m already stuck at the ajax request. What’s wrong with my code (i get alwas a ‘0’ response even though i have die() in the php function…)??
in my header.php:
<script type="text/javascript"> var count = 2; var total = <?php echo $wp_query->max_num_pages; ?>; jQuery(window).scroll(function(){ if (jQuery(window).scrollTop() == jQuery(document).height() - jQuery(window).height()){ if (count > total){ return false; }else{ loadArticle(count); //viewsite(); } count++; } }); function loadArticle(pageNumber) { jQuery.ajax({ url: ajaxurl, type:'POST', data: { action: 'ozinfinite_scroll', page_no: pageNumber }, success: function(html){ jQuery("#inf-cont-1").append(html); } }); return false; } </script>
functions.php:
function ozinfinite_scroll(){ // $loopFile = $_POST['loop_file']; $paged = $_POST['page_no']; $posts_per_page = get_option('posts_per_page'); # Load the posts query_posts(array('paged' => $paged )); get_template_part( 'contentoz', 'blog' ); die(); } add_action('wp_ajax_ozinfinite_scroll', 'ozinfinite_scroll'); // for logged in user add_action('wp_ajax_nopriv_ozinfinite_scroll', 'ozinfinite_scroll'); // if user not logged in function add_ajaxurl_cdata_to_front(){ ?> <script type="text/javascript"> //<![CDATA[ ajaxurl = '<?php echo admin_url( 'admin-ajax.php'); ?>'; //]]> </script> <?php } add_action( 'wp_head', 'add_ajaxurl_cdata_to_front', 1);
- The topic ‘Ajax requests give 0 response / infinite scroll’ is closed to new replies.