douwa0280 2018-06-29 05:38
浏览 64
已采纳

刷新后,AJAX实时搜索的数据消失了(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.

  • 写回答

1条回答 默认 最新

  • dongxixia6399 2018-06-29 05:46
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable