0

我有一个使用通用 HTML 元标记每 240 秒自动刷新一次的网页。在刷新期间,它会从数据库中提取数据,该数据库需要大约 15 到 20 秒的时间来构建网站,然后才会显示给用户。在此期间,我希望显示一个带有加载消息的小 DIV,告诉用户它正在加载数据。更复杂的是,用户有几个菜单选项可以从数据库中过滤掉特定数据。单击此类选项时,页面将再次重新加载,并且需要 15 到 20 秒才能构建。

不熟悉此加载时间的用户可能会觉得需要在几秒钟内一遍又一遍地单击相同的菜单选项,希望页面加载得更快。但相反,它很可能会导致数据库服务器因请求而过载。

因此,为了解决这个问题,我希望使用 jQuery 来显示加载消息,然后让它从数据库中加载数据(使用 PHP 脚本),最后将数据转储到页面上。

我做过类似的事情,但仅限于用户单击链接,该链接导致 jQuery 脚本在显示等待的 DIV 时加载数据(使用 CSS 规则)。

我不知道如何为自动刷新实现这个解决方案。

一些帮助会很好。

4

2 回答 2

0

I'd second megawac's comment. Don't use a meta refresh. Also, 15-20 seconds is a very long time for generating a database report that is going to be generated every 4 minutes; odds are that you're bogging down your server pretty badly. Very few queries should really take that long, especially queries that need to be run nearly continually. I would strongly recommend refactoring your queries or doing some caching to speed things up. If you post some code, I'm sure people would be happy to look at it.

于 2013-10-28T15:49:03.010 回答
0

You can use the same solution with auto-refresh as well, with the mention that the initial page load doesn't container the data that requires the DB call, but instead shows a loading message and starts an AJAX call to a server side script that returns the data.

Your page load:

  1. Request
  2. Server query DB
  3. DB Response
  4. Page loads (with data)

Ideal page load:

  1. Request
  2. Page loads (without data) <- loading message here
  3. AJAX call
  4. Server query DB
  5. DB Response
  6. Page updates (with data)
于 2013-10-28T15:40:04.287 回答