Start function by Onclick

0

Good afternoon Friends.

My question is the following, I have a script that basically reads a .log in real time and shows it on the screen, but the question is that it starts with the DOM, I'd like it to start only from the click of the button , could you 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>
    
asked by anonymous 27.07.2017 / 19:05

3 answers

0

Thanks for the @Leonardo return. I did this, but it still does not work:

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

Change this

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

for this

$(document).ready(function( ) {
$('.log-btn').click(function()) {
        $.repeat(1000, function() {
            $.get('automacao_tela.php?ajax&s=<?=$randomSession;?>', function(data) {
                $('#tail').append(data);
            });
        });
    });                    }
    
27.07.2017 / 20:38
0

Matheus I believe is loading directly because the $(document).ready(function()) function is being called. The right one is you create a class or an id for the button in html and call it in jQuery type so $(".btnclass").click(function()) .

    
27.07.2017 / 19:18