我无法从多页面布局表单提交的 AJAX 响应链接回主页
结构
index.php
具有多页协议(protocol) (index.php#agreement
)
#agreemen
t 有一个使用默认 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/