I have a PHP script that opens a port and asks the server if it is running, with PHP I echo a "Server Running" or an error - I want to access this script with JQuery/AJAX. Then on the website, I have a little box on the side of the screen that pulls the results of this script every 5 seconds or so and shows the user if the server is running.
What I am trying to accomplish is this: As the Javascript is accessing the script to see if the server is running, I want a <span> or <div> to say "Checking..." and then upon the data from the script being placed in it's own div, the "Checking..." goes away, then the process repeats.
I've got everything figured out with the HTML, Here is the JS I have so far:
<script type="text/javascript">
$(document).ready(function(){
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function(){
$('#serverresultsloading').html('Checking...');
$('#serverresults').load('ajax-calls/serverstats.php');
$('#serverresultsloading').html(' ');
}, 2000);
});
</script>
Inside of setInterval, the call to the php script works great but the message is always ' '. If I change the order of the lines inside setInterval to
$('#serverresultsloading').html('Checking...');
$('#serverresults').load('ajax-calls/serverstats.php');
$('#serverresultsloading').html(' ');
Then after 2 seconds I see "Checking..." but it never goes away.
So how should/can I go about this to get the desired result. I've tried a number of things, such as using wait(); with no results.
Thanks for your help