jQuery 移动刷新按钮
当我向数据库添加新内容时遇到问题,页面未更新。所以我想添加一个刷新按钮。
希望我能做到这一点吗?
I am having problems when I add new content to the database the pages are not updated. So I was thinking of adding a refresh button.
Hope can I do this please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您遇到的问题与 jQuery Mobile 缓存页面的方式有关。
location.reload(true)
不会工作,因为 URL 将包含哈希字符串。原因:
为了模拟本机移动转换,jQuery Mobile 执行 Ajax 请求并在 first 页面内插入
元素,本质上是从多页网站创建一个单页网站(内置导航、书签)。
解决方案:
然而,团队对于如何处理与时间相关的内容缺乏一点远见。我个人已经通过向我想要获得新副本的链接添加属性来解决该问题。
这会监听点击事件(点击,等等),删除缓存的 div 并让 jQuery 请求一个新的副本。
注意:
对此有多种解决方案,例如
data-ajax="false"
和rel="extenal"
,但是这些会阻止导航系统发挥作用。完整程度。此外,jQuery 团队也意识到了与此相关的问题,并且目前正在进行完整的导航重写。 http://jquerymobile. com/blog/2011/05/13/jquery-mobile-team-update-week-of-may-9th/。The problem you are having has to do with how jQuery Mobile caches pages. And
location.reload(true)
Will Not Work as the URL will have a hash string.Reason:
In order to emulate native mobile transitions jQuery Mobile performs a Ajax request and inserts the
<div data-role="page">
element inside the first page, essentially creating a single page site from a muti-page one (with navigation, bookmarking built into it).solution:
However the team has lacked a little foresight into how to deal with time dependent content. I personally have fixed the issue by adding a attribute to my links that I want to get a fresh copy.
This listens to a click event (tap, whatever), removes the cached div and lets jQuery request a fresh copy.
Note:
There are over solutions to this such a
data-ajax="false"
andrel="extenal"
however these will stop the navigation system to functionality to function to it's full extent. Also the jQuery team is aware of the issues surrounding this and are currently working of a full navigation rewrite. http://jquerymobile.com/blog/2011/05/13/jquery-mobile-team-update-week-of-may-9th/.您不需要 jQuery 来刷新页面。您只需要调用
location.reload(true)
。通过将第一个(也是唯一的)参数设置为
true
,我们强制从服务器刷新,而不仅仅是从缓存中重新加载页面。You don't need jQuery to refresh the page. You just need to call
location.reload(true)
.By setting the first (and only) argument to
true
we force a refresh from the server, and not just reload the page from the cache.