title: How to automatically reload the ajax/jQuery table data after a button click
body: <p>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.</p>
  <p>I tried some codes to make it work. How can I fix it?</p>
  <pre><code>$(document).ready(function() {
          $.getJSON(&quot;http://mydevtest.in/wp-json/pmprocurrencies/v1/all&quot;, function(data){
              var currency_Data = '';
              
              $.each(data, function(key, value){
                  currency_Data += '&lt;tr&gt;';
                  currency_Data += '&lt;td&gt;' + value.id + '&lt;/td&gt;';
                  currency_Data += '&lt;td&gt;' + value.country_alpha + '&lt;/td&gt;';
                  currency_Data += '&lt;td&gt;' + value.currency_code + '&lt;/td&gt;';
                  currency_Data += '&lt;td&gt;' + value.currency_sign + '&lt;/td&gt;';
                  currency_Data += '&lt;td&gt;' + value.currency_rate + '&lt;/td&gt;';
                  currency_Data += '&lt;td&gt;&lt;button type=&quot;submit&quot; id=&quot;delBtn&quot; value=&quot;' + value.id + '&quot;&gt;x&lt;/button&gt;&lt;/td&gt;';
                  currency_Data += '&lt;/tr&gt;';
              });
              $(&quot;#currency_tables&quot;).append(currency_Data);
              // Reload the table data on &quot;#addcr&quot; button click. 
              $(&quot;#addcr&quot;).on(&quot;click&quot;, function(){
                  $(&quot;#currency_tables&quot;).load(location.href + &quot; #currency_tables&quot;);
              });
              
          });
    
      });
  </code></pre>