用户向下滚动页面时(与Twitter和Facebook相似)从数据库延迟加载 [英] Lazy load from database as user scrolls down page (similiar to Twitter and Facebook)

查看:77
本文介绍了用户向下滚动页面时(与Twitter和Facebook相似)从数据库延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个优惠券代码网站.在某些类别页面上,我将其限制为仅显示50张优惠券,因为每个类别可能有1000张优惠券.我不会全部显示它们,因为这很难在服务器上显示,并且浏览器将挂起.随着用户不断向下滚动,是否有可能懒加载更多优惠券?

I have a coupon code site. On some category pages I'm limiting it to display only 50 coupons as there are potentially 1000's of coupons for each category. I don't display them all as it would be hard on the server, and the browser will hang. Is it possible to lazy load more coupons as the user keeps scrolling down?

我发现的唯一延迟加载插件是用于图像的.有什么可以与PHP配合使用并从MySQL数据库加载数据的东西吗?

The only lazy load plugins I've found are for images. Anything out there that will work with PHP and loading data from a MySQL db?

感谢您的帮助.谢谢!

推荐答案

为此,您肯定需要javascript或jquery.例如,当滚动条位于75%时,只需使用onScroll事件,即可使用AJAX调用php文件,并为查询传递2个参数.使用SQL限制,您需要设置开始指示符和要收集的行数: SELECT * FROM tbl_coupons LIMIT 50,20

You will definitely need javascript or jquery for this. Just use an onScroll event when the scroll-bar is for example at 75% call a php-file using AJAX, pass 2 parameters for the query. Using the SQL Limit you need to set the start-indicator and the number of rows you want to collect: SELECT * FROM tbl_coupons LIMIT 50,20

您可以使用让php输出要使用的html并将html直接插入到Dom中,或者如果您想使用JS解析数据,则可以使用* json_encode *从数组中创建一个json-object行.

You can use let the php output the html you want to use and insert the html straight into the Dom or if you want to parse the data using JS you can use *json_encode* to create a json-object from an array of rows.

这篇关于用户向下滚动页面时(与Twitter和Facebook相似)从数据库延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆