Jquery无限滚动和XML
我见过一些插件,当您滚动到页面底部时会加载更多内容,但其中大多数都链接到数据库中具有自动增量 ID 的列。我只需要使用 XML 文件来完成此操作。
有什么想法吗?
非常感谢。
I have seen a few plugins that load more content when you scroll to the bottom of the page, but most of these are linked to a column in a database with an autoincremented id. I need to do this only with an XML file.
Any ideas?
Much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将 XML 发送到客户端,这将导致浏览器解析它并构建 DOM。根据它的大小(几千字节?兆字节?),这可能很快,也可能需要一段时间。默认情况下将所有 if 发送到浏览器也会占用您的带宽,是的,某种程度上违背了延迟加载的目的。
然而,无限滚动是一种 UI 范例,因此您可以实现它,即使您总是将整个 XML 文件发送到浏览器。同样,这取决于您想要实现的目标 - 节省带宽或只是“即时”创建内容。
假设您将文件留在服务器上,因为它太大了:
来自无限滚动插件的假设请求可能如下所示
然后您的 data.aspx 将使用 XPath 查询从第 516 个元素检索 10 个 XML 元素:
然后您可以从中构造 HTML 或将其作为原始 XML 发送并通过以下方式进行评估客户端上的 jQuery。
可能有定制的框架可以完成所有这些工作,但如果我要实现这样一个系统,以上大致就是我会做的。
If you send your XML down to the client, this will cause that the browser parses it and builds a DOM. Depending on how large it is (A few kilobytes? Megabytes?) this can be fast, or it can take a while. Sending all of if to the browser by default also hogs your bandwidth and yes, somehow defeats the purpose of lazy loading.
Infinite scroll however is a UI paradigm and as such you can implement it even though you always send the entire XML file to the browser. Again it depends on what you want to achieve - conserve bandwidth or just create content "on the fly".
Supposing you leave the file on the server because it is so large:
A hypothetical request from an infinite scroll plugin could look like
And your data.aspx would then use an XPath query to retrieve 10 XML elements from 516th element on:
You would then either construct HTML from that or send it as raw XML and evaluate that via jQuery on the client.
There are probably tailored frameworks that do all this, but if I were to implement such a system, the above is roughly what I would do.