donljt2606 2015-01-03 17:05
浏览 49

在自定义joomla组件上实现ajax url / browser历史记录的最佳方法

I was assigned a task to modify a custom joomla component's search functionality that is only done through ajax, and doesn't have any url/query string handling, so the users cannot go to previous searches through browser back button as well as it is impossible to bookmark a specific search query for sharing etc.

Currently, the search is done by a jquery script that collects all of the form elements' selected values on the page and sends that (with ajax) to a separate controller task (ajax.ajaxSearch) which echoes json with all available results. In the view then there is a code that parses that json and builds an ul list for all items. And the url stays always the same (it's the homepage currently).

What I was thinking to do is in the script that receives the items from the model, to set some history handling ie:

var params = '&beds=2&fireplace=1&kitchen=1';
history.pushState(params, null, '?task=search'+params);

With this I will have urls like www.mysite.com/properties/?task=search&beds=2&fireplace=1&kitchen=1 with back button working and params will be saved in the window.state object which hopefully I could use to re-run the ajax search query with the selected params. And I know I will have to code couple of methods that will take care of such routes like www.mysite.com/properties/?task=search&beds=2&fireplace=1&kitchen=1 to be properly handled when accessed directly.

What I want to know is the approach described above feasible to go after? Is there a maybe better solution that could solve this problem more elegantly and easily ? What would your approach be if faced with similar task?

  • 写回答

1条回答 默认 最新

  • dtdvlazd56637 2015-01-03 20:15
    关注

    You can try some history frameworks but anyway if you want the back button to work you need an anchor to move back and foward. I don't see why it shouldn't work.

    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致