【问题标题】:PhoneGap apk not executing POST actionPhoneGap apk 未执行 POST 操作
【发布时间】:2017-01-17 14:36:27
【问题描述】:

在我的 PhoneGap 应用中,我有这段代码来测试 AJAX REST 通信:

$( document ).ready(function() {
        $("#test").click(function() {
        alert("OK");
        $.ajax({ 
        type: "GET",
        data: {},
        url: "http://localhost:8080/test-notifier-web/RegisterServlet",
        });
    });
});
<div class="row col-centered">
    <button type="submit" id="test">Submit</button>                 
</div>

在 Chrome 中执行此代码没问题,我可以登录控制台,一切正常。当我使用 cordova build android 构建 apk 并在我的 Genymotion 设备上对其进行测试时,我没有收到来自服务器的响应。有的时候,用Genymotion浏览器通过web测试是可以的。

我用这段代码创建了一个新的空白应用程序,它与 apk 配合得很好。谁能帮帮我?

这是我的 config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="it.paytas.mobile" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>Paytas Mobile</name>
    <description>
        A blank PhoneGap app.
    </description>
    <author email="support@phonegap.com" href="http://phonegap.com">
        PhoneGap Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="DisallowOverscroll" value="true" />
</widget>

【问题讨论】:

  • 粘贴您的 config.xml 和 Content-Security-Policy
  • @Eric 发布了 config.xml,我在哪里可以找到 Content-Security-Policy?

标签: android cordova


【解决方案1】:

您需要将“allow-intent”元数据添加到您的 config.xml

<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

您需要将 Content-Security-Policy 元数据添加到您的 index.html

<meta http-equiv="Content-Security-Policy" content="default-src 'self' gap://ready file://* 'unsafe-inline' *; style-src 'self' 'unsafe-inline' *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; img-src *">

还要确保您已安装 cordova-plugin-whitelist 插件。

【讨论】:

  • 这正是我的问题。已经解决了,谢谢
猜你喜欢
  • 1970-01-01
  • 2020-11-18
  • 1970-01-01
  • 2019-04-19
  • 2019-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多