phpjqueryajaxlivesearchurl-modification

AJAX live search's data goes away after refreshing (PHP)


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.


Solution

  • 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.