Start function by Onclick

Asked

Viewed 294 times

0

Boa Tarde Amigos.

My question is this, I have a script that keeps reading one. log basically in real time and shows it on screen, but the point is that it starts with the DOM, I would like it to start only from the click on the button, could help me ??

<?php
    if (isset($_GET['ajax'])) {
        $sessionID = 'log'.$_GET['s'];
        session_id($sessionID);
        session_start();
        $handle = fopen('/\\cordas\instance-8480\log\server.log', 'r');
        if (isset($_SESSION['offset'])) {
            $data = stream_get_contents($handle, -1, $_SESSION['offset']);
            echo nl2br($data);
        } else {
            fseek($handle, 0, SEEK_END);
    } 
      $_SESSION['offset'] = ftell($handle);
      exit();
    }

    $randomSession = rand();

?>

<script>
        $(document).ready(function( ) {
            $.repeat(1000, function() {
                $.get('automacao_tela.php?ajax&s=<?=$randomSession;?>', function(data) {
                    $('#tail').append(data);
                });
            });
        });
  </script>

<form action="?automacao=ok" method="POST">
    <button type="submit" class="log-btn" >INICIAR PROCESSO</button>
</form>

 <div id="tail" class="widget-stats-list-log">
    Starting up...
 </div>

2 answers

1


Change this

<script>
    $(document).ready(function( ) {
        $.repeat(1000, function() {
            $.get('automacao_tela.php?ajax&s=<?=$randomSession;?>', function(data) {
                $('#tail').append(data);
            });
        });
    });

for that reason

$(document).ready(function( ) {
$('.log-btn').click(function()) {
        $.repeat(1000, function() {
            $.get('automacao_tela.php?ajax&s=<?=$randomSession;?>', function(data) {
                $('#tail').append(data);
            });
        });
    });                    }
  • Thank you for the friendly reply, but it still hasn’t worked that way.

0

Thanks for the feedback @Leonardo. I did it this way, but it still doesn’t work:

$('.log-btn').click(function()) {
            $.repeat(1000, function() {
                $.get('automacao_tela.php?ajax&s=<?=$randomSession;?>', function(data) {
                    $('#tail').append(data);
                });
            });
        });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.