JQM(jQueryMobile)访问URL历史记录?

时间:2011-03-24 16:39:02

标签: jquery ajax history jquery-mobile

我遇到的问题是能够从多页面布局表单提交的AJAX响应链接回主页

结构

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

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

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

我可以轻松地放置href="index.php",但会话会丢失它的值。

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

我已在agreement.php

中使用此代码绑定index.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>

2 个答案:

答案 0 :(得分:1)

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

agreement.php后退按钮代码,使用data-rel =&#34;返回&#34;锚标记中的选项并添加名为/ id agreement_status

的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页面时,页面隐藏会发生什么,因此您将在#agreement页面上。然后使用window.history.back();我们可以返回index.php页面并仍然保持所有数据的固定而无需刷新页面

答案 1 :(得分:0)

试试这个

        window.location.href = "/index.php";
相关问题