1

Hi there I am trying to append HTML to a list to create an infinite scroll effect, please do not reply by telling me to use a plugin.

I know from the inspector that onClick() is generating the HTML correctly via the PHP script it calls however the HTML generated is not being appended to the rest of the document.


Here's my code (JQuery has been imported):

HTML:

    <body>
        <div id='container'>
            <?php include 'inc/header.php'; ?> 
            <?php include 'inc/nav.php'; ?>

            <section class="grid-wrap">
                <ul class="grid swipe-right custom-grid" id="grid">
                    <?php
                        $files = glob('img/gallery/*.{jpg,png,gif,JPG}', GLOB_BRACE);

                        $total = 9; //count($files);

                        for ($i = 0; $i < $total; ++$i) {
                            echo "<li><a href='" . $files[$i] . "' target='_blank'><img class='lazy' src='" . $files[$i] . "' alt= 'Image of Sheila' /><h3>View Full Image</h3></a></li>";
                        }
                    ?>
                </ul>   

              <div id='load-more'>VIEW MORE PHOTOS</div>
            </section>


            <?php include 'inc/footer.php'; ?>

        </div>

        <script>
            $('#load-more').click(function(){
                $.ajax({
                    url: 'inc/gallery/gallery2.php',
                    dataType: 'html',
                    sucess: function(php){$('.grid-wrap').append(php);}
                });
            });
        </script>
    </body>

gallery2.php :

        <?php
            $files = glob('../../img/gallery/*.{jpg,png,gif,JPG}', GLOB_BRACE);
            $total = 9;
            $id = 1;

            echo '<ul class="grid swipe-right custom-grid" id="grid' . $id . '">';

            for ($i = $total; $i < ($total + 9); ++$i) {
                echo "<li>
                        <a href='" . $files[$i] . "' target='_blank'>
                            <img src='" . $files[$i] . "' alt= 'Image of Sheila' />
                            <h3>View Full Image</h3>
                        </a>
                      </li>";
            }

            $total+= 9;
            echo '</ul>';
        ?>
1
  • 3
    I think you mis-typed 'success' as 'sucess' for your ajax callback. Commented Sep 2, 2014 at 10:02

3 Answers 3

3

Just a repost of my comment :x.

I think you mis-typed 'success' as 'sucess' for your ajax callback.

Sign up to request clarification or add additional context in comments.

Comments

1

As Renald Lam said, you mis-typed success as sucess:
change this:

sucess: function(php){$('.grid-wrap').append(php);

to:

success: function(php){$('.grid-wrap').append(php);

Comments

1

U missing s in success function and try

$('#load-more').click(function(){
    $.ajax({
        url: 'inc/gallery/gallery2.php',
        dataType : 'html',
        success: function(php){
           $('.grid-wrap ul').append(php);
        }
    });
});

1 Comment

HERP DE DERP DERP. It always something like that. All working as expected now, cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.