How to call Ajax with jQuery periodically in WordPress?
<p>I want to update information in a WordPress widget every 30 seconds. Therefore I thought I'd better use some Ajax. </p>

<p>I found this here on the <a href="https://codex.wordpress.org/AJAX_in_Plugins" rel="nofollow">WordPress Codex</a> and added it to my functions.php:</p>

<pre><code>add_action( 'admin_footer', 'my_action_javascript' ); // Write our JS below here

function my_action_javascript() { ?&gt;
&lt;script type="text/javascript" &gt;
jQuery(document).ready(function($) {

    var data = {
               'action': 'my_action',
               'whatever': 1234
    };

    // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    jQuery.post(ajaxurl, data, function(response) {
        alert(response);
    });
});
&lt;/script&gt; &lt;?php
}

add_action( 'wp_ajax_my_action', 'my_action_callback' );

    function my_action_callback() {
    global $wpdb; // this is how you get access to the database
    $bla = get_option("airtime_now_playing");
    echo $bla;
    wp_die(); // this is required to terminate immediately and return a proper response
}
</code></pre>

<p>It works fine and does retrieve what I need. </p>

<p>How can I fire this not only once but every 30 seconds?</p>

<p>Thanks a lot!</p>