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 would like it to start just from the click of the button, could you help me? / p>
<?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();
$(document).ready(function( ) {
$.repeat(1000, function() {
$.get('automacao_tela.php?ajax&s=<?=$randomSession;?>',
function(data) {
$('#tail').append(data);
});
});
});
<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>
----- Adding code ----
<body>
<div class="automacao-container">
<div class="automacao-box">
<div class="row">
<div class=" col-sm-3">
<div class="stats-widget">
<div class="widget-header">
<h2>Automação</h2>
</div>
<div class="widget-stats-list" id="lerLog">
<form action="?automacao=ok" method="POST">
<button type="submit" class="log-btn">INICIAR PROCESSO</button>
</form>
</div>
</div>
<div class="stats-widget" style="height: 495px;">
<div class="widget-header">
<h2>Parâmentros</h2>
</div>
<div class="widget-stats-list">
</div>
</div>
</div>
<div class=" col-sm-9">
<div class="stats-widget">
<div class="widget-header">
<h2>Log de Automação</h2>
</div>
<div id="tail" class="widget-stats-list-log">
Starting up...
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$('#lerLog').on('click', function( ) {
$.repeat(1000, function() {
$.get('automacao_tela.php?ajax&s=<?=$randomSession;?>',
function(data) {
$('#tail').append(data);
});
});
});
</script>
</body>