javascript - Ajax Load more Script Bug? -
hey test loadmore script found online. not loading content when done scrolling down. loading when complete scrolled xd !
what wrong ?
here code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript"> $(window).scroll(function() { if($(window).scrolltop() == $(document).height() - $(window).height()) { $('div#loadmoreajaxloader').show(); $.ajax({ url: "loadmore.php", success: function(html) { if(html) { $("#postswrapper").append(html); $('div#loadmoreajaxloader').hide(); }else { $('div#loadmoreajaxloader').html('<center>no more posts show.</center>'); } } }); } }); </script> <div id="postswrapper"> <div class="item">content</div> hey<br> hey<br> hey<br> hey<br> hey<br> hey<br> ---- more added here cutted out cause long! ---- hey<br> <div id="loadmoreajaxloader" style="display:none;"><center><img src="ajax-loader.gif" /></center></div> </div>
loadmore.php contains echo , example div contents ..
console empty.
thanks :)
edit
here working jsfiddle copied still same problem... codegaze fiddle.
edit 2 here code working in jsfiddle!
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript"> $(document).ready(function () { $(window).scroll(function () { if ($(window).scrolltop() == $(document).height() - $(window).height()) { alert("this end"); } }); }); </script> <div id="postswrapper"> <div class="item">content</div>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey <br>hey --- cutted out more--- <br>hey <br>hey <br>hey <br>---- more added here cutted out cause long! ---- hey <br> <div id="loadmoreajaxloader" style="display:none;"> <center> <img src="ajax-loader.gif" /> </center> </div>
i downloaded source example found online... , working ... different can see on first view includes jquery 1.4.4 ????
github example source
here jsfiddle plain html , works fine. think should add $(document).ready()
shown in fiddle ;)
update: construct page required tags valid html page , code work. code simple, doesn't matter witch jquery version use.
this simple html page. add contents , check result.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>document</title> </head> <body> </body> </html>
Comments
Post a Comment