基于 Ajax 的建议列表和替换
我正在尝试在我的网站上创建一个建议项目列表,类似于 Facebook 的“建议朋友”列表。
我有一个包含 10 个建议项目的列表,它来自 mysql 查询。 用户可以选择“x”该项目或接受该项目,然后应使用 AJAX 替换该列表项。替换项来自同一查询,但不一定是原始表中的第 11 项。 mysql查询会根据用户的输入而改变。
我能想到的实现这一目标的唯一方法是让 jquery 获取所有 10 个项目的 ID,将它们发送到 AJAX,AJAX 将提取查询并比较列表,然后吐出新的项目。
这看起来很混乱,并且可能向 AJAX 发送了不必要的信息量。有没有更聪明的替代方案?
I'm trying to create a suggested items list on my website, similar to that of Facebook's "suggested friends" list.
I have a list of 10 suggested items, which comes from a mysql query.
The user has an option to 'x' the item or accept the item, after which that list item should be replaced using AJAX. The replacement item comes from the same query, but not necessarily the 11th item in the original table. The mysql query will change based on the user's input.
The only way I can think to accomplish this is to get jquery to grab the ID's of all 10 items, send them to AJAX which will pull up the query and compare the lists, and spit out the one that is new.
This seems messy, and probably an unnecessary amount of information being sent to AJAX. Is there a more clever alternative to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想,你不能完全避免查询过程,但你可以做下一步:
例如获取 100 个项目的数量,然后用 JS 处理它们以显示前 n 个项目
现在你可以通过以下方式最大限度地减少对服务器的请求量:定义一次加载的项目数量。
I guess, you can not totally avoid the query process, but you can do next:
Get an amount of 100 items for example, then process them with JS to show the n first items
Now you can minimize the amount of requests to the server by defining the amount of items to load at a time.