Button refresh data from a query without refresh on page [duplicate]

-3

I'm creating an application in PHP (Codeigniter) and I came across the following situation. I have a table on my page that brings all the results of a query into the database. I want to create a refresh button but I did not want the refresh button on the page. I'd like some help on how I can do this.

Thank you in advance.

    
asked by anonymous 18.09.2015 / 13:46

1 answer

2

Use Jquery to make an AJAX request.

When you click on the refresh button you make a request on the server returning a json with your desired result in your case I believe a list populates your table.

Example:

$("#btnRefresh").click(function(){
      $.get(aquisuaurlqueretornajson)
         .done(function(response){
            $("#nomedatabela tbody tr").remove();//limpar os dados já populados
                for(var i in response){

                    var linhaTabela = $("<tr><td> " + response.algumatributodoseujson + "  </td>" + "</tr>");
                    $("#nomedatabela").append(linhaTabela);

                    }
    });
    
18.09.2015 / 15:26