jQuery mobile:URL查询字符串不变 [英] jQuery mobile: URL query string does not change

查看:64
本文介绍了jQuery mobile:URL查询字符串不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩jQuery Mobile,遇到了一些(对我来说)奇怪的行为.

我有一堆链接,每个链接都指向同一个jQM页面#otherpage,但是URL查询字符串的值不同,例如#otherpage?q=foo#otherpage?q=bar等.切换到另一页效果很好,但查询字符串在两次单击之间仍然停留,因此,如果我先单击指向#otherpage?q=foo的链接,然后返回到第一页,则所有随后的对#otherpage的页面更改都将具有q=foo ,无论当前单击的链接的href怎么说.

jsFiddle似乎不支持jQM,因此我在此处举了一个例子: http ://cpak.se/dump/location-search-test.html

我已经在Mac上的Chrome和Safari中尝试过此操作.

我使用查询字符串在页面之间传递简单数据,因为我还有其他代码挂接到pagechange事件中,这或多或少不了解以前的代码可能做了什么.如果无法正常工作,我将不得不寻找另一种传递数据的方法...:P

干杯!

/克里斯托弗(Christofer)

解决方案

我一直在寻找这个问题,因为它看起来确实有些奇怪.对此有一个公开的问题: https://github.com/jquery/jquery-mobile /issues/2859

Atm jQuery Mobile不建议使用查询参数:

我们目前不支持将查询参数作为哈希的一部分 片段,尽管这是经常讨论的问题 内部,并且在功能请求列表中.

他们建议使用类似以下的插件

:

但是,有一种解决方法,因为DOM DOES中活动页面的数据URL发生了变化,您可以使用$(".ui-page-active").attr("data-url");检索它,我已经在您的网站上对其进行了测试,并且它给了我所有3个唯一URL.

I'm playing around with jQuery Mobile and ran into some (for me) strange behavior.

I have a bunch of links each pointing to the same jQM page, #otherpage, but with different values for the URL query string, like #otherpage?q=foo, #otherpage?q=bar, and so on. The change to the other page works fine but the query string sticks between clicks, so if I first click the link to #otherpage?q=foo, and then goes back to the first page, all subsequent page changes to #otherpage will have q=foo, no matter what the currently clicked link's href says.

jsFiddle didn't seem to have support for jQM so I put an example here: http://cpak.se/dump/location-search-test.html

I've tried this in Chrome and Safari on Mac.

I use the query string to pass simple data between pages since I have other code hooked into the pagechange events, that is more or less unaware of what earlier code might have done. If I can't get this working I'll have to find another way to pass data around... :P

Cheers!

/Christofer

解决方案

I've looked up for this issue because it seems a little bit weird indeed. There is a open issue about this: https://github.com/jquery/jquery-mobile/issues/2859

Atm jQuery Mobile doesn't recommend using query parameters:

We don't currently support query parameters as part of the hash fragment, though this is something that's been discussed frequently internally and is on the feature request list.

They advise to use a plugin like:

However, there is a workaround since the data-url of the active page in the DOM DOES change, you can retrieve this with $(".ui-page-active").attr("data-url"); I've tested this on your website and it gave me all 3 uniques URLs

这篇关于jQuery mobile:URL查询字符串不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆