skip to Main Content

I have a button on my page that executes a .sh script which writes to connection_check.txt. The issue I’m running into is that after the script has ran, the old version/data is still shown on the page as it doesn’t seem the page gets fully refreshed after the .sh has ran so the old data is still cached. Or maybe its because I have $_SESSION set because apart from write to a file, the .sh also echos a value that unhides the divs.

I’m very unfamiliar with html and php. My div looks like this.

<div class="connection_details" id="connection_details_id" style="display:none;">
<p><?php include('connection_check.txt'); ?></p>
</div>

I also tried adding this to no avail..

<?php if ($output1 == 1) : ?>
<script>
document.getElementById("connection_details_id").style.display = "block";
</script>
$("#connection_details_id").load(location.href + " #connection_details_id");
<?php endif ?>

How can I make sure connection_check.txt is retrieved again after running the .sh and changing style.display to block??

2

Answers


  1. Chosen as BEST ANSWER

    Found a solution myself.

    <?php if ($output1 == 1) : ?>
    <script src="jquery-2.1.1.min.js" type="text/javascript"></script>
    <script>
    $("#connection_details_id").load('connection_check.txt')
    </script>
    <script>
    document.getElementById("connection_details_id").style.display = "block";
    </script>
    <?php endif ?>
    

    Might not be pretty but it works.


  2. I’m not sure, How do you run the .sh script, However run the following code after you run it

    $("#connection_details_id").load("connection_check.txt?val=" + Math.floor(Math.random() * 101) );
    

    Also, take a look at AJAX

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search