I have a PHP program that does a task for a indeterminant time that I want to kick off in javascript and then contunue the javascript after the PHP is complete. I could put a timer for the lonest time the PHP can take but would be better if we had a way to know the PHP was finisihed. Any help appeciated.
In the page with the JS you start an interval, and then point the src of another JS to your PHP page. <script type="text/javascript"> var process = function() { do_stuff(); } var processing = setInterval(process, 1000); </script> <script type="text/javascript" src="script.php"></script> Code (markup): Then in "script.php" you print some javascript that will clear the interval at the end. <?php do_stuff_in_php(); echo 'clearInterval(processing);'; ?> Code (markup):
Trying joebert's concept function countClickHandler ( ) { if ( document.getElementById("countButton").value == "Click me!" ) { // Start the timer document.getElementById("countButton").value = "Enough already!"; countIntervalId = setInterval ( "count()", 1000 ); } else { document.getElementById("countMessage").innerHTML = ""; document.getElementById("countButton").value = "Click me!"; clearInterval ( countIntervalId ); } } function count ( ) { if ( Math.random ( ) > .5 ) var process = function interval() var processing = setInterval(process, 2000);</script> <script type="javascript"> src="uhits.php";</script> <script type="text/javascript"> document.getElementById("countMessage").innerHTML = "Woo!"; else var process = function interval() var processing = setInterval(process, 2000);</script> <script type="javascript"> src="uhits.php";</script> <script type="text/javascript"> document.getElementById("countMessage").innerHTML = "Yay!"; setTimeout ( 'document.getElementById("countMessage").innerHTML = ""', 500 ); } </script> <div id="countMessage" style="height: 50px; font-size: large; color: red; width: 300px">This is the hits Generator</div> <input type="button" name="clickMe" id="countButton" value="Click me!" onclick="countClickHandler()"/> Does not execute the uhits.php
<script type="javascript"> src="uhits.php";</script> Code (markup): Should be <script type="javascript" src="uhits.php"></script> Code (markup):