使用 Phonegap Build 构建后,Phonegap AJAX 请求无法在 Android 设备上运行

Phonegap AJAX requests not working on Android device after build with Phonegap Build

我的问题:

使用 Phonegap Developer 应用进行开发时,一切正常。但是在我使用 Phonegap Build 构建我的应用程序后,我的 AJAX 请求似乎不起作用。

重要提示:

我采取的步骤:

依赖项版本:

@JustDevelop,
您犯了两 (2) 个常见错误。

  1. 首先,您不能使用通过 Phonegap 桌面应用程序 创建的文件并在 Phonegap Build 上使用这些文件。您可以在 Phonegap CLI 中使用这些文件,但不能在 Build 中使用。它的工作方式不同。您需要从自己的样板文件或已知的工作样板文件开始。

  2. 您将需要使用 whitelist 系统,但它在三 (3) 年内发生了很大变化。从今天 (2015-12-23)

  3. 起,请勿关注超过 6 个月的任何 post、博客或建议

关于 #1, 这是让您入门的样板 Phonegap--Generic-Boilerplate7 In addition, the following blog post will work for development and make you familiar with what you need.
An HTML Boilerplate for Phonegap
将两者作为生产参考,但不作为发布

在#2 上, 作为 Joergejcesarmobile 暗示你可能需要添加whitelist 系统到您的应用程序。如果您的 index.html 中有内联或块 Javascript,则需要使用 CSP如果没有,那么你只需要使用带有过滤器的whitelist插件。如果没有,那么带有过滤器的whitelist插件可能就足够了。

内联 javascript <button onclick="doSomething();">do something</button>

块javascript<script>doSomething() function() {return something;}</script>

如果您确实遇到 whitelist 问题,请使用本指南和以下代码:

HOW TO apply the Cordova/Phonegap the whitelist system

将此添加到您的 config.xml

<plugin name="cordova-plugin-whitelist"      source="npm" spec="1.1.0" />
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" /> <!-- Required for iOS9 -->

请注意,您的应用现在不安全。保护您的应用程序取决于您。
将以下内容添加到您的 index.html 这是您的 CSP 修复程序。

<meta http-equiv="Content-Security-Policy" 
         content="default-src *; 
                  style-src * 'self' 'unsafe-inline' 'unsafe-eval'; 
                  script-src * 'self' 'unsafe-inline' 'unsafe-eval';">

最后 FWIW,您可以考虑开设一个 github 帐户。 Public 帐户是免费的。私人账户收费。您可以将代码直接从计算机传输到 github,传输到 Phongap Build。

此外,如果有任何帮助解决您的问题,请告诉我们。