Mirakurun Mirakurun - 3 months ago 12x
jQuery Question

Javascript pressing the button in an interval

I have a submit button, which sends the value with POST method to the same page.

<button id="log" class="btn bg-purple" formmethod=post value="2" name="start" formaction=start_server.php>Get Log</button>

When I press that button, I get the log from the file in a list using PHP.

What I want to do now is to make a script with javascript to automatically press the "Get Log" button to reload the log file every 2 seconds so I can have an interactive log, without pressing the button myself.

I have tried this script, but only the alert is working I guess, since it doesn't reload the log file at all.

<script type="text/javascript">
var auto = setTimeout(function(){ autoRefresh(); }, 100);

function submitform(){

function autoRefresh(){
auto = setTimeout(function(){ submitform(); autoRefresh(); }, 2000);


Replace your script with this:

    // this handles the click on yout "Get log" button
        console.log("Click function");

    // This sets an interval to simulate a click every 2 seconds.
    auto = setInterval(function(){
        console.log("Interval iteration");
    }, 2000);