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.
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:
And the second:
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!