No-code adding AJAX to search results paging in SharePoint 2010
Search Paging – the classic way
We all know this scenario: you search for something…
you find some results…
and then you find some more results…
Every time you move to another page of the search result, SharePoint redirects you to another page, which is convenient, given that you can bookmark the link or send it over to someone else.
While this works, what if you’re looking for a more dynamic experience, one that doesn't require a whole page reload?
Enhancing the search experience with AJAX
Instead of reloading the whole page, every time you switch between search result pages, you could just refresh the search results and the pager. Did you know that you can do this without custom development?
Important: Although the solution presented in this article uses AJAX, it’s from the visual point of view only. Behind the scenes the whole search results page is being retrieved, so there is only little performance gain from implementing this solution.
Let’s start with creating a new search results page:
Next go to the edit mode and in the Rich Text Editor add the Search Core Results, Search Paging and the Content Editor Web Parts.
Tip: To avoid vertical scrolling, which might look awkward in combination with AJAX, you should limit the number of search results per page so that the Search Paging Web Part is visible at all times.
Additionally, to hide the Content Editor Web Part from the visitors, you can set its Chrome Type to None.
Next edit the HTML source of the Rich Text Editor and surround both search Web Parts with:
Then edit the contents of the Content Editor Web Part and in the HTML Source view paste the following code snippet:
Confirm your changes and publish the search results page.
If you search now, and use the pager to switch to another page of search results, you should see that the URL in the browser’s address bar remains unchanged while the Search Results and Search Paging Web Parts reflect search results for the search results page of your choice.
How it works
If you have examined the requests and responses made after switching between pages, you might have noticed that the whole search results page is being retrieved from the server. This is required for two reasons. First of all we have no server-side code at our disposal, so we can either get the results from the search results page itself, or use SharePoint Web Services to execute the search query. The second reason, for which we get the search results directly from the search results page, is the fact that the XML returned by SharePoint Search is transformed using XSL which is defined in the Search Core Results Web Part. If we loaded the results from the Web Services we would have to ensure that they are rendered exactly the same as by the original Search Core Results Web Part which might not be trivial.