0

So currently I'm searching for 10 new posts from the page and use $_GET['limits'] in my PHP query.

So what I'd like to do is if there is no new data to show the 'No More Posts' Div. I tried an on error alert function with no luck.

var streams_stream_count=10;    
function streams_stream_load(targetID){
    $('#loadmorestreamoneajaxloadertarget').show();
    $.ajax({
        method: 'get',
        url : 'stream2.php?limits='+streams_stream_count+'&targetID='+targetID,
        dataType : 'text',
        success: function (t) { 
            $('#streams_stream_container').fadeIn('slow').html(t); 
            $(document).scroll(function(){
                if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
                    streams_stream_count+=10;streams_stream_load(targetID);
                }
            });
        },
        complete: function(){
            $('#loadmorestreamoneajaxloadertarget').hide();
      }
  });
}

And my hidden div to show if no new data.

<div id='nomoreposts' style='display:none;'>No more Posts</div>

1 Answer 1

1

You'll have to do it in your success callback as you're not getting an error, you're just getting no data. So, if t here is an array, you could just do something like: if ( t.length === 0 ) { // show no more posts }

Hope this helps. Best.

Richard

4
  • Hi Richard, sounds like a great suggestions, only I have tried putting it in my success just before the page scroll doing if no data show div else show scroll more data. Doesn't seem to work . Thank you Nov 27, 2015 at 23:28
  • What did happen when you did that? And did you put that in an if else block?
    – R.A. Lucas
    Nov 27, 2015 at 23:36
  • It just kept loading and searching for more data. And yes I did. I just don't know if it was in the right place. Nov 27, 2015 at 23:38
  • Can you add that code that you tried in the success function that failed?
    – R.A. Lucas
    Nov 28, 2015 at 1:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.