Search code examples
mysqlajaxpaypalwaithandle

AJAX - timed mySQL queries (please wait screen)


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.


Solution

  • 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.