Bring data like facebook's wall

0

I'm implementing a functionality to bring data like the post's mural of facebook, apparently it's not very difficult, however, I have a question and would like to know if anyone has a solution or suggestion for this problem of mine.

The code

$(document).scroll(function(){
  if ($(window).scrollTop() + $(window).height() == $(document).height()) {
    pesquisar("","");
  }
});

In the code above, I have a function that does an ajax execution to return certain data, however, I would like to refresh the page with new data and not repeating them which is what happens to me at the moment. I tried the find ('div') function. Remove () to have a supposed 'update' of data, however, this is horrible, the user loses the reference where the scroll is and ends up returning to the beginning. Would anyone have a better suggestion for adding the information without repeating the content already added?

    
asked by anonymous 13.03.2017 / 21:09

1 answer

0

Try to use the function AppendTo ('# element') or isertAfter ("# element"), both will keep the current content and add new content to the end of the element passed as a parameter.

It would look like this:

//insere os dados dentro do container, no final.
$(dadosVindosDoAjax).appendTo("#containerDePosts");

or:

//este insere os dados depois da ultima postagem
$(dadosVindosDoAjax).insertAfter($("#containerDePosts").find("#postagens").last());
    
14.03.2017 / 13:32