InfiniteAjaxScroll TypeError: $ is undefined

1.9k Views Asked by At

Hi I am trying to use Infinite Ajax Scroll in Silverstripe.

The setup is as described in the Getting Started Page http://infiniteajaxscroll.com/docs/getting-started.html and the "jquery-ias.min.js" is referenced with an include statement on my Page.ss Template AFTER including jquery.js

But regardless how I am trying, I get: TypeError: $ is undefined

Any idea what I am missing out? THX!

Page.ss

<% require javascript('framework/thirdparty/jquery/jquery.js') %>
<% require javascript('framework/thirdparty/jquery-tools/jquery.tools.min.js') %>
<% require javascript('framework/thirdparty/jquery-ias.min.js') %>
<script type="text/javascript" src="{$ThemeDir}/javascript/script.js"></script>    

script.js

jQuery.noConflict();
// jQuery.noConflict(); <-- uncommenting jQuery.noConflict solves it!

(function($) {
    $( document ).ready(function() {

        var ias = jQuery.ias({
          container:  '#posts',
          item:       '.post',
          pagination: '#pagination',
          next:       '.next'
        });
     });
}(jQuery));

Markup

<div id="posts">
    <div class="post">...</div>
    <div class="post">...</div>
</div>

<div id="pagination">
    <a href="/page2/" class="next">next</a>
</div>
1

There are 1 best solutions below

0
On BEST ANSWER

The solution is to leave jQuery.noConflict(); away!

// jQuery.noConflict(); <-- uncommenting jQuery.noConflict solves it!

(function($) {
    $( document ).ready(function() {

        var ias = jQuery.ias({
          container:  '#posts',
          item:       '.post',
          pagination: '#pagination',
          next:       '.next'
        });
     });
}(jQuery));