0

I have an error related to AJAX Live Search.

When I search something from the Database, it searches the data and shows me the results of the data being searched, but when I refresh the page, the data goes away.

I need for the URL to become localhost/site/search.php?q=search_data using the GET method in PHP when searching for something.

In AJAX, what I am currently doing is using GET and the URL as url: "localhost/site/search.php?q=" + search_data, and so I'm able to get the data eventually, but I want to modify the URL to localhost/site/search.php?q=search_data because otherwise whenever anyone wants to bookmark the specific search result page, it won't be able to be done and the data will go away.

N8888
  • 630
  • 2
  • 13
  • 20
  • So you want a live search to behave like a non-live search? If you want the search results to have a specific URL, you need to use something like [history's pushState](https://developer.mozilla.org/en-US/docs/Web/API/History) to manipulate the URL using JS while the user is searching. Then you also need to build a feature that checks the URL when the user enters the page so you can remake that search. – Magnus Eriksson Jun 29 '18 at 05:42
  • Here you can find your answer I hope this will help you https://stackoverflow.com/questions/5999118/how-can-i-add-or-update-a-query-string-parameter – F5 Buddy Jun 29 '18 at 06:11

1 Answers1

0

The url could be updated by using histoy.pushState function in js. The code should be like:

history.pushState(null, null, "?q=" + search_data);

You can use it to update state/url after ajax request and on refresh it will pass the same parameters as you require.

Lovepreet Singh
  • 4,404
  • 1
  • 12
  • 34