【问题标题】:jQuery .load() not working with PhoneGap Build and jQuery MobilejQuery .load() 不适用于 PhoneGap Build 和 jQuery Mobile
【发布时间】:2015-05-28 15:46:42
【问题描述】:

我正在开发一个 jQuery Mobile Web 应用程序。它是一个 index.html 文件,其中包含多个页面,使用 data-role="page"。每个页面都使用相同的页眉和页脚,所以我使用.load() 在我的项目中加载单独的 html 文件。

这在 Chrome 中按预期工作,但在我将应用程序安装到运行 iOS 8.3 的 iPhone 时却不行。页眉和页脚根本不加载。

/*** load headers and footer ***/
$(document).on('pageinit', function() {
    /* header */
    $('.customHeader').load('../templates/header.html');
    /* footer */
    $('.customFooter').load('../templates/footer.html');
    /* dining */
    $('.banner.dining').load('../templates/dining.html');   
});

【问题讨论】:

  • 除了将域列入白名单之外,您是否找到了解决方案?

标签: jquery-mobile phonegap-build


【解决方案1】:

我的 jQuery 在 phonegap 上也无法为我工作。有几件事,我改变了。希望这会有所帮助。

您是否将代码包装在文档 onready() 上?

$(document).ready(function() {

)}:

由于某种原因,当我准备好文档时,它就可以工作了。网络的工作方式不同。

另外,请确保您的 jquery 包含在您的脚本之前。除非这些在我的代码之前,否则我的 jQuery 将无法工作:

<script src="lib/jquery.min.js"></script>
<script src="lib/jquery-ui.min.js"></script>

【讨论】:

  • 感谢您的回复。我的代码包含在$(document).on('pageinit', function() {}); 中,但是当我尝试$(document).ready(function() {)}: 时不起作用我的源顺序也是正确的。我最后加载了我的自定义脚本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多