jQuery BBQ 漂亮的 URL
我正在使用 BBQ jquery 插件进行 AJAX 历史管理,但在获取“漂亮的网址”时遇到问题。我已经尝试了我能想到的一切,但希望我错过了一些愚蠢的事情,并且有人可以指出我正确的方向。
我正在序列化一个表单,仅用于填充的输入,以避免哈希片段中出现空查询。警报解码URIComponent正在按照我想要的方式显示字符串,但我仍然以#hashfragment=key%26value%3Dkey%26value
结束
有人可以帮忙吗?相关代码如下。
stateQuery = $('#searchUsers :input[value]').serialize();
stateQuery = decodeURIComponent(stateQuery);
// Push the state into history and replace any other keys
$.bbq.pushState({ search: stateQuery }, 2);
谢谢。
I'm using the BBQ jquery plugin for AJAX history management, but I'm having a problem getting 'pretty urls'. I've tried everything I can think of, but hopefully I'm missing something stupid and someone can point me in the right direction.
I'm serializing a form for only inputs that are filled to avoid empty querys in the hash fragment. Alerting decodeURIComponent is showing the string how I want it, yet I'm still ending up with #hashfragment=key%26value%3Dkey%26value
Can anyone help? The related code is below.
stateQuery = $('#searchUsers :input[value]').serialize();
stateQuery = decodeURIComponent(stateQuery);
// Push the state into history and replace any other keys
$.bbq.pushState({ search: stateQuery }, 2);
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了解决问题的方法,虽然不像干净的参数字符串那样优雅,但直到我找到其他方法为止。
在推送状态之前,使用 jQuery bbqs param.fragment.noEscape 函数转义一些不重要的字符(遗憾的是尝试转义 & 和 = 会阻止状态功能工作),然后替换 '=' 和 '&'字符串中的字符被推入状态。
然后,在获取状态时,在将其推送到函数以更新页面之前,将分隔符重新替换为“=”和“&”一切都进展顺利。
Well, I found a solution to my problem, not quite as graceful as a clean string of parameters but until I figure something else out it'll do.
Before pushing the state, use jQuery bbqs param.fragment.noEscape function to unescape some unimporant characters (sadly trying to escape & and = stops the state functionality from working), then replace '=' and '&' characters in the string being pushed into the state.
Then when getting the state, before pushing it to a function to update the page re-replace the delimiters with '=' and '&' and everything passes through just fine.