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

标签 jquery ajax history jquery-mobile

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

结构

index.php 具有多页协议(protocol) (index.php#agreement)

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

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

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

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

我已在 index.php 中使用此代码绑定(bind)了 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>

最佳答案

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

agreement.php 后退按钮代码,在 anchor 标记中使用 data-rel="back"选项,并添加一个带有 name/idgreece_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();
});

当协议(protocol)状态页面隐藏时,页面隐藏会触发,因此您将位于#agreement 页面上。然后使用 window.history.back();我们可以返回到index.php页面,并且仍然保留所有数据,而不需要刷新页面

关于jquery - JQM (jQueryMobile) 访问 URL 历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5422492/

相关文章:

c - 为什么FILE像FILE *一样大写?

javascript - 将附加的 html 附加到 jquery 中的克隆对象

javascript - jQuery .ajax() - 向 POST 请求添加查询参数?

javascript - XMLHttpRequest 通过但不是我的 Jquery Ajax 调用调用相同的东西

php - Drupal 7 : Database Query file

javascript - .back 和 .pushState - 两个历史的故事

jquery - 如何按一定比例缩放DIV的所有内容?

javascript - Devbridge 自动完成,没有结果

jquery - 我们可以使用 nanoscroller 进行水平滚动吗?

python - raw_input 不在 readline 中留下历史记录