AJAX - 定时 mySQL 查询(请等待屏幕)

发布于 2024-08-12 18:29:17 字数 192 浏览 5 评论 0原文

我需要创建一个 AJAX 页面,在页面加载时查询数据库,然后每 5-10 秒查询一次。与此同时,我将显示某种等待页面(可能带有动画 gif 来让我的客户开心:))

我正在与 paypals IPN 合作,所以它是在我等待交易清算时使用的。大多数时候它在用户返回之前清除,但有时不会。因此,如果有人有这样的代码或者可以向我指出这样的代码的方向,那就太好了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅听莫相离 2024-08-19 18:29:17

http://www.w3schools.com/js/js_timing.asp(允许您在 X 秒内做某事)
http://docs.jquery.com/Ajax/jQuery.get (是否AJAX 请求)

使用 setTimeout 和 jQuery get 轮询您的脚本。让脚本响应 IPN 请求的状态。使用 jQuery get 解析脚本的响应,并确定是否应该显示等待图像或告诉用户一切已成功。

希望这能为您指明正确的方向。

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.

我偏爱纯白色 2024-08-19 18:29:17

对于任何其他正在寻找“请稍候”脚本的人 - 这个脚本是一个很好的起点:

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

我所要做的就是替换

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

为:

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;
}

然后在 boo.php 中

我让它查询我的 IPN 状态列。

希望这对其他人有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文