• Resolved Franchi Web Design

    (@franchidesign)


    as the title suggests I get this error. (Notice: Undefined index: page in /Users/denis/Sites/www.testpepe.dev.cc/wp-content/themes/bubi/functions.php on line 429)
    Php code:

    <?php
    function bubi_ajax_script_load_more($args) {
        // Init ajax
        $ajax = false;
        // Call AJAX
        if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
            strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
            $ajax = true;
            
            }
        //Number Paged
    /* Line 429 */  $paged=$_POST['page'] + 1;
        // Number Article
        $num =4;
        //Args
        $args = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'posts_per_page' =>$num,
            'paged'=> $paged,
        );
            
            
        //Query
        $query = new WP_Query($args);
        if ($query->have_posts()):
            //loop articales
            while ($query->have_posts()): $query->the_post();
                //include articles template
                include 'template-parts/content-archive-design.php';
            endwhile;
        else:
            echo 0;
        endif;
        wp_reset_postdata();
        //Call AJAX
        if($ajax) die();
    
    }

    JS code:

    <script>
    jQuery.noConflict($);
    /* Function AJAX */
    jQuery(document).ready(function($) {
    
    var eseguito = false;
    
    //Scroll Position
    $(window).scroll(function() {
    
        var $timeline_block = $('.cd-timeline-block');
    
        //hide timeline blocks which are outside the viewport
        $timeline_block.each(function(){
            if($(this).offset().top > $(window).scrollTop()+$(window).height()*0.75) {
                $(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden');
            }
        });
    
        //on scolling, show/animate timeline blocks when enter the viewport
        $(window).on('scroll', function(){
            $timeline_block.each(function(){
                if( $(this).offset().top <= $(window).scrollTop()+$(window).height()*0.75 && $(this).find('.cd-timeline-img').hasClass('is-hidden') ) {
                    $(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in');
                }
            });
        });
            
            //Init
            var that = $('#loadMore');
            var page = $('#loadMore').data('page');
            var newPage = page + 1;
            var ajaxurl = $('#loadMore').data('url');
            
        if (eseguito) {
            if ($(window).scrollTop() <= ($(document).height() - $(window).height())*0.75){
                eseguito = false;
            } else {
                return false;
            }
        }
            
        if (!eseguito) {
            
      
            if ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.75){
                
        eseguito = true;
                
            //Call AJAX
            $.ajax({
                url: ajaxurl,
                    type: 'post',
                    data: {
                            page: page,
                            action: 'ajax_script_load_more'
                    },
                    error: function(response) {
                            console.log(response);
                    },
                    success: function(response) {
                            
                            if (response == 0) {
                        
                                if ($("#no-more").length == 0) {
                                    $last =  ( 'placeholder', bubi_scripts_ajax_vars.placeholder_name);
                                        $('#ajax-content').append('<div id="no-more" class="text-center"><h3>'+$last+'</h3></div>');
                                }
                                $('.bubi_loader_ajax__dot').hide();
                            } else {
                                $('#loadMore').data('page', newPage);
                                $('#ajax-content').append(response);
                            }
                    }
                });
            }
        }
        });
    });
    </script>

    The code works fine, but in debug mode I get the error as per the title, how can I solve this problem? Thank you.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Undefined index: page in loop load ajax content’ is closed to new replies.