简体   繁体   English

缓慢的php / mysql结果-显示加载图像?

[英]Slow php/mysql results - display loading image?

I have a website that is running php/MySQL to query and return results. 我有一个运行php/MySQL的网站来查询和返回结果。 The result set is over 40,000 and the query is getting slower. 结果集超过40,000,查询速度越来越慢。 I want to find a simple way to display a loading image while the page builds. 我想找到一种在页面构建时显示加载图像的简单方法。 I can do it with any page running JavaScript but I assume since php is server side I need to handle the loading differently. 我可以在运行JavaScript的任何页面上执行此操作,但是我认为由于php是服务器端,因此我需要以不同的方式处理加载。

I see that AJAX has a load() function where I can call the php page and presumable show a loading image while the request is loading. 我看到AJAX具有load()函数,可以在其中调用php页面,并且在请求加载时大概显示加载图像。 Is that the best way? 那是最好的方法吗? I can't believe that there aren't lots of example scripts floating around since this has to be a very common problem. 我不敢相信没有太多示例脚本,因为这肯定是一个非常普遍的问题。

Are you using an AJAX request to do this? 您是否正在使用AJAX请求来执行此操作? If so, it's as simple as using JavaScript to display an image when you send the request, then hide it again upon success/error. 如果是这样,就像发送请求时使用JavaScript显示图像一样简单,然后在成功/错误时再次将其隐藏。 You can just keep an <img> tag around with "display: none" and turn it on/off as needed. 您只需在<img>标记周围加上“ display:none”,然后根据需要将其打开/关闭即可。

If you aren't using AJAX, then this will be impossible, as the page does not exist until the query is completed. 如果您不使用AJAX,那么这将是不可能的,因为在查询完成之前该页面不存在。

On a side note: it's incorrect to say that "AJAX has a load() function". 附带说明:说“ AJAX具有load()函数”是不正确的。 AJAX is not a code base or a library, it is a technique. AJAX不是代码库也不是库,它是一种技术。 Perhaps you mean jQuery.ajax, or some other library? 也许您是指jQuery.ajax或其他库?

您必须使用Ajax,我估计使用PHP和AJAX数据从表单加载到MySQL中将非常有用,并遵循jQuery API以获得Ajax参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM