samedi 9 mai 2015

How to empty the GET values from a MySQL/jQuery ajax call

If you do an ajax call to retrieve info from a MySQL database and you time the function so it runs every X seconds, I am a bit confused about where do the GET values reside, in order to empty them.

I have this code in test.js:

var fill = function () {
    $.ajax({
    type: "GET",
    url: "refresh.php",
    dataType: "html",
    success: function( data ) {
    $( "#tb" ).append( data );
        setTimeout( fill, 5000);
        }
 });
 } ;

and in refresh.php I have the SQL query to retrieve the info. After the query, I setting the table like this:

    printf( "<tr><td>".$row['name'].
"</td><td>".$row['surname'].
"</td><td>".$row['phone'].
"</td><td>".$row['date'].
"</td></td></tr>");

How can I stop the table from populating the same row every 5 seconds? I can pass the $row['name'] values to regular php values if needed, but I don't fully get in which moment I should empty them.

Aucun commentaire:

Enregistrer un commentaire