Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
How to automatically reload the ajax/jQuery table data after a button click

I have created a jQuery/ajax API call function to read the JSON data and insert it into the HTML table and it works fine, But I want to auto-reload the table data after 5Sec when a button is clicked.

I tried some codes to make it work. How can I fix it?

$(document).ready(function() {
        $.getJSON("http://mydevtest.in/wp-json/pmprocurrencies/v1/all", function(data){
            var currency_Data = '';
            
            $.each(data, function(key, value){
                currency_Data += '<tr>';
                currency_Data += '<td>' + value.id + '</td>';
                currency_Data += '<td>' + value.country_alpha + '</td>';
                currency_Data += '<td>' + value.currency_code + '</td>';
                currency_Data += '<td>' + value.currency_sign + '</td>';
                currency_Data += '<td>' + value.currency_rate + '</td>';
                currency_Data += '<td><button type="submit" id="delBtn" value="' + value.id + '">x</button></td>';
                currency_Data += '</tr>';
            });
            $("#currency_tables").append(currency_Data);
            // Reload the table data on "#addcr" button click. 
            $("#addcr").on("click", function(){
                $("#currency_tables").load(location.href + " #currency_tables");
            });
            
        });
  
    });
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use setTimeout(function,milliseconds) for this. https://developer.mozilla.org/en-US/docs/Web/API/setTimeout

about 4 years ago · Juan Pablo Isaza Denunciar

0

So, I was able to find the solution myself, below is the working code, But I think it's not the professional solution to repeat the same function to achieve the result. If anyone has any better idea, Please suggest.

$(document).ready(function() {
        $.getJSON("http://mydevtest.in/wp-json/pmprocurrencies/v1/all", function(data){
            var currency_Data = '';
            
            $.each(data, function(key, value){
                currency_Data += '<tr>';
                currency_Data += '<td>' + value.id + '</td>';
                currency_Data += '<td>' + value.country_alpha + '</td>';
                currency_Data += '<td>' + value.currency_code + '</td>';
                currency_Data += '<td>' + value.currency_sign + '</td>';
                currency_Data += '<td>' + value.currency_rate + '</td>';
                currency_Data += '<td><button type="submit" id="delBtn" value="' + value.id + '">x</button></td>';
                currency_Data += '</tr>';
            });
            $("#currency_tables").html(currency_Data);
            // Reload the table data on "#addcr" button click. 
            
            
        });

        $("#addcr").on("click", function(){
            setTimeout(function(){
                $.getJSON("http://mydevtest.in/wp-json/pmprocurrencies/v1/all", function(data){
                var currency_Data = '';
                
                $.each(data, function(key, value){
                    currency_Data += '<tr>';
                    currency_Data += '<td>' + value.id + '</td>';
                    currency_Data += '<td>' + value.country_alpha + '</td>';
                    currency_Data += '<td>' + value.currency_code + '</td>';
                    currency_Data += '<td>' + value.currency_sign + '</td>';
                    currency_Data += '<td>' + value.currency_rate + '</td>';
                    currency_Data += '<td><button type="submit" id="delBtn" value="' + value.id + '">x</button></td>';
                    currency_Data += '</tr>';
                });
                $("#currency_tables").replaceWith(currency_Data);
                // Reload the table data on "#addcr" button click. 
            });
            }, 4000)
        });
  
    });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda