1
I have a script that reads 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();
$(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>
----- Addition of 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>
Good Morning Bsalvo, I did everything as you said, I put the id on the button and entered the Onclick in the function, only now it does not read the log does not start, and if I take onClick in the function, it works normally, no longer know what to do :/
– Matheus
Calm that we will solve, take a test and create a div to be clicked. Forget the button and test now on a div. Don’t forget to bring me the feedback!
– Bsalvo
Good morning, it still hasn’t worked even with a div, I’ll put all my code in the answer can it be ? so I can take a closer look and tell you what I’m missing ?
– Matheus
Put there, the function I provided should already be working
– Bsalvo
placed as an answer below
– Matheus
Matheus, it’s mehlro add as edit on the question. Here is just for same answers.
– Bsalvo
Matheus a div with id='lerLog'' needs to be on top of the function code... First div after the code
– Bsalvo
Bsalvo, I put as an addition the code to which I spoke, but in the same way it still doesn’t work, only works if I leave as posted in the question above the addition.
– Matheus
Huum. very strange.. You are clicking on START PROCESS? if so it is likely that n will actually work. Please delete that id='lerLog' you put there and add that div <div id='lerLog'>By clicking here the reading of the log will happen</div> anywhere above the function, just for test purposes and tell me if it works.
– Bsalvo
Now with a separate div, it worked.O, I have no idea what could have happened. Does not have a way to put behind the button ??
– Matheus
Matheus does not need the <form> tag in this situation, the type of the button is type='Submit' that means it works directly with the form, you can try to change the type to type='button' and add the id='lerLog' (I don’t think this will work) or you can also follow my advice, and delete this form and this button and style a div so it stays the way you want it. If you can mark my answer, thank you :)
– Bsalvo
Thanks for the reply Bsalvo, unfortunately I can not take the Form because I use it for another function take his post of 'ok', but I will do the tests here changing the Submit to button, and if nothing works I will take the div that worked and put behind the invisible button. I thank you very much for the help colleague. I have already marked the answer. Thank you.
– Matheus
Just to complement, your idea of switching from "Submit" to "button" worked, I just need to figure out a way to send the form now kkk
– Matheus
Every time the form is sent the log should also be updated? If so I have the quick answer for you.
– Bsalvo
That’s right, every time I send the form, a . txt is generated on the server, and I go there and pick up this . txt, and show on screen the log in real time.
– Matheus
My button runs cmd which starts a file . bat, which generates this txt, and shows it on screen.
– Matheus
Matheus, is there any other way we can talk? It is not very good to extend the subject so much in the comments of the reply not to disturb future readers.
– Bsalvo
Here it works ?
– Matheus
Email me, [email protected]
– Matheus