Forum Moderators: open
Here is the script:
<head>
<script type="text/javascript" src="mootools.js"></script>
<script type="text/javascript">
window.addEvent('domready',init);
xhr = null;
function init() {
checking = check.periodical(10000); // number of milliseconds, so this checks every 10 seconds
$('stopper').addEvent('click',function() { $clear(checking); }); // this is just to stop it and you probably wouldn't have it
}// End init()
var check = function() {
if(xhr == null)
xhr = new XHR({method: 'get',onSuccess: receive});
// Here's where we send the request - id gets passed as a parameter; I'm assuming you need to pass something
// so the checking script can look it up in the database. You could alternatively set it as a SESSION variable and leave
// the second parameter off entirely.
xhr.send('http://www.example.com/checkfinished.php','id=1');
}// End check()
function receive() {
$('msg').setHTML(xhr.response.text); // This just echoes the response, and could be skipped.
// This is what you'll be interested in modifying - doing something relevant when this if() is true.
if(xhr.response.text == 'OK') {
$clear(checking);// This turns off the 10 second check.
} // EndIf the wait is over
}// End receive()
</script>
</head>
<body>
<div id="msg">Waiting</div>
<button id="stopper">Stop waiting</button>
</body>
I have the mootools.js file, but I'm still running into problems with it. When I go to the page, it displays normally for the first check cycle (i.e. 10 sec). Then, whether it's got the correct response or not from the php page, it loads the php page IN the processing page (like an i-frame) rather than redirecting.
Also, I want to pass the session var suggested in the line:
xhr.send('http://www.example.com/checkfinished.php','id=1');
The var has been set previously by php as $_SESSION['hash']; how eactly do I code that into the above line?
Last, the AJAX script waits for an 'OK' message from the php page. How do I code that into the php? I tried adding 'echo "OK";' after getting the DB result, but: a) it doesn't work, and b) when the user redirects to the php page, won't the user see "OK" along with my configured display?
Any help is appreciated.