0

I am having issues with (I believe) setInterval on a div.

The setInterval loads my "panic.php" page which shows if there is a row in the panic table. I need to continuously reload the div until the row has been deleted and I thought setInterval was my best option...

jQuery Code (js/panic.js)

setInterval(function () {
    $("#panicInfo").load("process/GET/panic.php");
  }, 1000);

PHP code (process/GET/panic.php)

$stmt = $conn->prepare("SELECT `rpname`, `location` FROM panic");
$stmt->execute();
$stmt->bind_result($panicrpname, $paniclocation);
$stmt->store_result();
$stmt->fetch();
if ($stmt->num_rows == 1) {
    echo '
    <div class="row mt-5 justify-content-center">
        <div class="col-md-10">
            <div class="alert alert-panic">
                <div class="text-center display-6 mb-3">ALERT</div>
                    <div class="text-center mb-3">
                        Panic button has been pressed by ' . $panicrpname . '. 
                    </div>
                    <div class="text-center mb-3">
                        Please respond to <b>' . $paniclocation . '</b> immediately.
                    </div>
                    <div class="mt-3 text-center">
                        <button type="button" class="btn btn-outline-light" id="clearPanicBtn">
                            Respond & Clear
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    ';
}
$stmt->close();

My issue is I cannot click the button whatsoever.

I've tried to get a button outside of the div to clear the panic alert, but it is more code to add to continuously check if a row exists and if not, don't show the button to clear..

  • 1
    What specifically do you mean by "cannot click the button"? Is something preventing the mouse from actually clicking at that location on the screen? Are you successfully clicking the button but it just doesn't do what you expect? What do you expect it to do and why? – David May 09 '23 at 16:59
  • It is like the button resets, same thing if I use setInterval on a form - the form resets every x interval... The button is supposed to clear that row in the database. – Jerrett Smith May 09 '23 at 17:07
  • If I were you I will , instead of using setinterval, write an ajax calling the PHP , which on success of the ajax call (and depends on the result), re-trigger the same ajax until the condition meets what you want and terminate the ajax call. – Ken Lee May 09 '23 at 17:36

0 Answers0