views:

150

answers:

2

I need to make an AJAX page which queries the database on page load and then every 5-10 seconds after that. In the meantime I will display some kind of waiting page (maybe with a animated gif to keep my customers entertained :) )

I am working with paypals IPN so its for while I am waiting for the transaction to clear.. most of the time it clears before the user returns, but sometimes it does not. So if anyone has such code or could point me in the direction of such code that would be great.

A: 

http://www.w3schools.com/js/js%5Ftiming.asp (Allows you to do something in X seconds) http://docs.jquery.com/Ajax/jQuery.get (Does an AJAX request)

Use setTimeout and jQuery get to poll your script. Have the script respond with the status of the IPN request. Use jQuery get to parse the script's response and figure out if you should be showing a waiting image or telling the user everything that it was successful.

Hopefully that will point you in the right direction.

William
A: 

For anyone else looking for a 'please wait' script - This one makes an excellent starting point:

http://www.aleixcortadellas.com/main/2009/02/15/automatically-query-mysql-and-output-results-with-ajax/

All I had to do was replace

document.getElementById(divid).innerHTML=xmlHttp.responseText;

With:

switch(xmlHttp.responseText)
{
case '0':
  document.getElementById(divid).innerHTML='<img src="wait.gif" />';
  break;
case '1':
  location.href="http://www.google.com";
  break;
case '-1':
  document.getElementById(divid).innerHTML='ERROR: Your transaction failed, please contact us';
  break;
}

And then in boo.php

I made it query my IPN status column.

Hope this helps someone else.

Mark