Append Infinite arrays returned from PHP to AJAX

Asked

Viewed 42 times

1

function CheckNewsFeed() {
$.ajax({
  url: ProcurarPorNovosDados.php,
  success: function(texto) {
  *Aqui que está minha dúvida, como fazer o Append de resultados dinâmicos
  retornado pelo PHP?*
  //$("#Resultados").html(texto);
  }
})};

setTimeout(CheckNewsFeed(), 3000);

I have no idea how to do this, and I don’t know if it’s possible, but every comment helps, thank you;

1 answer

2


The name couldn’t be more inviting: jQuery.append.

// Como você utilizará #resultados infinitas vezes,
// coloque-o em cache, assim a busca no DOM ocorre apenas uma vez
var $resultados = $('#resultados');

function CheckNewsFeed() {
$.ajax({
    url: ProcurarPorNovosDados.php,
    success: function(texto) {
        $resultados.append(texto); // faz append do novo resultado
    }
})};

setTimeout(CheckNewsFeed(), 3000);
  • independent from the results list in mysql?

  • 1

    When you configure the callback Success to $.ajax method it is already understood that you are returning text/html ready to be attached to the page, mainly because you have not detailed anything else. And, jQuery knows nothing about your Mysql, all it expects there is a return, no matter what you do in your PHP. What then do you mean by result list in Mysql? As I said it is expected that in your PHP you return only text/html/JSON. So, if you get from Mysql, first do the processing in PHP and return the text.

  • 1

    Yes, I will make the results have their <div’s> in PHP itself, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.