jquery动态分页

发布于 2025-01-01 21:56:14 字数 477 浏览 0 评论 0原文

我有这个脚本,允许显示 Bing 搜索结果: JsFiddle 演示

问题是它只能显示一次 50 个结果。所以我想做一个分页。到目前为止,我有这段代码,它允许显示结果的第二部分,其中 var WebOffset = "Web.Offset=0";

$("#page2").click(function() {
    WebOffset = "Web.Offset=1";
    var searchTerms = getSearch();
    doSearch(searchTerms);
});

我的问题:我如何预测总共有多少结果,以便我现在知道要制作多少个分页号(div)。但更重要的是,这当然必须是“自动化”的。因此,代码必须根据 bing 结果总数显示一组 div(分页编号)。我真的不知道要开始解决这个问题。任何帮助表示赞赏。

I have this script which allows to display Bing search results: JsFiddle Demo

The problem is that it can only show up to 50 result at a time. So I want to make a pagination . So far I have this code which allows to display the second part of the results, with var WebOffset = "Web.Offset=0";

$("#page2").click(function() {
    WebOffset = "Web.Offset=1";
    var searchTerms = getSearch();
    doSearch(searchTerms);
});

My question: How can I predict how many results there are in total so that I would now how many pagination numbers (divs) to make. But more important this of course has to be 'automated'. So the code would have to display a set of divs(pagination numbers) based on the bing results in total. I really have no idea were to begin solving this problem. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿萝 2025-01-08 21:56:14

由于您必须具有一些服务器端逻辑才能获取结果,因此您可以在提交搜索查询时请求结果数并存储它,或者,您可以通过每个页面请求获取该数字。另外,由于您似乎正在使用 jQuery,因此这应该很容易。

这两种情况可能如下所示:

第一:

  1. 用户提交搜索查询
  2. 服务器返回第一页结果。
  3. 获取结果总数,用于分页控件
  4. 用户点击不同的页面(向服务器发送带有页码的请求)
  5. 服务器返回当前所选页面对应的结果

第二次:

  1. 用户提交搜索查询
  2. 服务器返回第一页结果,以及总结果数
  3. 用户点击不同的页面(向服务器发送带有页码的请求)
  4. 服务器返回与当前所选页面对应的结果

您可以看到,在第一种情况下,您必须在客户端存储总结果数。与第二个相反,在第二个中,您会在每个结果请求中收到它。

回家这有帮助。祝你有美好的一天!

Since you must have some server side logic in order to get the results, you can request the number of results when a search query is submitted and store it, or, you can get that number with each page request. Also, since it appears you're using jQuery, this should be easy.

Here is what these two scenarios could look like:

First:

  1. The user submits a search query
  2. The server returns the first page of results.
  3. Get total number of results, for pagination controls
  4. The user clicks different page (send a request to the server with the page number)
  5. The server returns the results that correspond to the currently selected page

And the second:

  1. The user submits a search query
  2. The server returns the first page results, along with the total results count
  3. The user clicks different page (send a request to the server with the page number)
  4. The server returns the results that correspond to the currently selected page

You can see that in the first scenario, you would have to store the total result count on the client side. As opposed to the second one, where you receive it with every result request.

Home this helps. Have a great day!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文