Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

Javascript code refuses to load before PHP

$
0
0

Ok so, this is part of a fancy "smart home" webpage im making, and I cant seem to get this code to run in the correct order, no matter what I do, even though I put a sleep() before the script execution, it refuses to show the success message before it runs the script that reboots the router (which is why I need it to show BEFORE, since this page isint available again until the router fully reboots). Hopefully someone can help me with this!

(At this point, #cover-spin is set to 0 and showing, hence why I set cover-spin.show to 1, to hide it before the message appears)

(yes, #cover-spin is a css class, no idea why I had to put it in javascript tags, but it does work if I put it in another PHP script that always runs on the page)

Heres the code:

if (0 == $status) {
    echo '<script type="text/javascript">';
    echo '$("#cover-spin").show(1)';
    echo '</script>';
    echo '<script type="text/javascript">';
    echo 'setTimeout(function () { swal("Success","Command was successfully sent","success");';
    echo '}, 0);</script>';
    sleep(3);
    exec("/var/www/html/router.sh");
} else {
    header("Location: ?error=true");
}

edit: something like this?

echo '<script type="text/javascript">';
    echo 'objXMLHttpRequest.open("GET", "router.sh");';
    echo 'objXMLHttpRequest.send();';
    echo '</script>';

Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>