【问题标题】:JQM (jQueryMobile) Access to URL history?JQM (jQueryMobile) 访问 URL 历史?
【发布时间】:2011-03-24 16:39:01
【问题描述】:

我无法从多页布局表单提交的 AJAX 响应链接回主页

结构

index.php有多页协议(index.php#agreement

#agreement 有一个使用默认 AJAX 调用提交到 (agreement.php) 的表单

从agreement.php 我可以回到预期的最后一页(#agreement),但现在我想回到index.php 页面。

我可以轻松输入href="index.php",但随后会话失去了它的价值。

有没有办法倒退两步?或访问 URL 历史记录并指向特定页面而不丢失表单中的任何数据?

我已经在index.php 中使用此代码绑定了agreement.php

$('#agreement_status').live('pageshow',function(event, ui){
    // Button action
    $('#back_home').click(function(){
        window.history.back(); // this goes back one page to index.php#agreement
        window.history.back(-2); // this goes back one page to index.php#agreement
        $.mobile.changePage("#index", "slideup"); // this works but appends the hashtag in the URL which breaks the other functionality 
    });
});

agreement.php我有这个代码

<a id="back_home" 
   data-role="button" 
   data-icon="home" 
   data-theme="z" 
   data-inline="true" 
   style="float:right;">
    Home
</a>

【问题讨论】:

  • 我目前在 changePage 中遇到了类似的问题,它可以正确重定向,但会在 URL 中留下一个标签,这会破坏一切。如果我找到解决方法,我会告诉你的。
  • 他们刚刚发布了ver a4,所以我很快就会测试它

标签: jquery ajax history jquery-mobile


【解决方案1】:

嗯,这不是我问题的真正答案,但它确实解决了我的问题:

agreement.php 后退按钮代码,在锚标签中使用 data-rel="back" 选项并添加带有 name/id 协议状态的 div 标签

<a data-rel="back" 
   data-role="button" 
   data-icon="home" 
   data-theme="z" 
   data-inline="true" 
   style="float:right;">
    Home
</a>

在 index.php 页面中,将其添加到您的 java 脚本中

$('#agreement_status').live('pagehide',function(event, ui){
    window.history.back();
});

当agreement_status 页面被隐藏时会触发pagehide,因此您将进入#agreement 页面。然后用 window.history.back();我们能够返回 index.php 页面,并且仍然保留所有数据,而无需刷新页面

【讨论】:

    【解决方案2】:

    试试这个

            window.location.href = "/index.php";
    

    【讨论】:

    • 这只是重定向,我会丢失任何 URL 参数以及任何已输入的未保存数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 2014-06-10
    • 2011-01-24
    相关资源
    最近更新 更多