开发者

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-开发者_JAVA技巧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.


http://www.w3schools.com/js/js_timing.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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜