There is a search form with a block of results with the restriction of output to 5 per page (pagination). The question is, what can you think of to save the previously selected filter search when you go by pagination?

  • Cookie, Local Storage - Deonis
  • Or save the filter in the session - BOPOH
  • or location.hash, like here sweetness.com.ua/uhod-za-licom - mountpoint
  • @Oleg Ponomarchuk, If you are given a comprehensive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

1 answer 1

There are at least 2 options if ajax is used:

  1. Save to js-variable and pass the filter value as a parameter to the next ajax request.
  2. Save the filter as an attribute to some invisible layout element.

Explanations:

filter = 'search_string=aaa&page=2'; ... var url = '/search.php?' + filter; 

or

 $('#hidden_element').attr('filter', 'search_string=aaa&page=2'); ... var url = '/search.php?' + $('#filter').attr('filter'); 
  • one
    good practice is to do a search so that the query parameters are visible in the address bar. To throw a link to a friend or save yourself and so on - mountpoint