javascript - jquery mobile - 如何在从外部链接返回后正确加载页面

标签 javascript jquery html css jquery-mobile

我创建了 JQM 网站,我在其中使用单页设计,这意味着我的 index.html 首先加载所有 .js、css 等文件。 我剩下的页面是带有 data-role="page" 的简单 Div。

当我浏览网站时,浏览器 URL 会发生变化,后退按钮也会起作用。 但问题是:

网站包含支付系统,为此,用户将从我的网站重定向到支付页面,成功/失败后,支付页面会尝试重定向回我网站的最后一个 URL,如下所示:

http://<ip>:<port>/appName/pages/page-name.html

但这并没有加载任何 css 或 JS 文件。

有什么方法可以保留上次 session ? 请帮我解决这个问题。

提前致谢

最佳答案

在 JQM 中,您不能直接链接到多页文档中的特定页面。

当您链接到包含多个页面的页面时,jQuery Mobile 的工作方式将默认加载第一页。您将需要使用 subpages plugin使用 AJAX 加载页面

您应该分隔页面或通过 AJAX(使用插件)预加载多页文档,然后将其作为内部页面链接

来自Documentation

Note: You cannot link to a multipage document with Ajax navigation active because the framework will only load the first page it finds, not the full set of internal pages. In these cases, you must link without Ajax (see next section) for a full page refresh to prevent potential hash collisions. There is currently a subpage plugin that makes it possible to load in multi-page documents

It's important to note that if you are linking from a mobile page that was loaded via Ajax to a page that contains multiple internal pages, you need to add a rel="external" or data-ajax="false" to the link. This tells the framework to do a full page reload to clear out the Ajax hash in the URL. This is critical because Ajax pages use the hash (#) to track the Ajax history, while multiple internal pages use the hash to indicate internal pages so there will be conflicts in the hash between these two modes.

关于javascript - jquery mobile - 如何在从外部链接返回后正确加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44150238/

相关文章:

php - 高端 Node.js 框架

jquery - Rails 4.2.7提交远程表单的事件触发两次

javascript - 使用 jQuery 在输入框中选择字符串的一部分

javascript - Jquery.switchclass 没有正确加载

javascript - Azure表存储通过javascript验证REST调用

javascript - *ngIf 不会在 else block 中切换回 false

jquery - 如何阻止页面刷新?

php - 通过 PHP 的 HTML 表单数据

javascript - saga React.js 中的 setTimeout 函数

jquery - 在jqgrid的列中添加图像