PhoneGap apk 未执行开机自检操作



在我的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 浏览器通过网络进行测试是可以的。

我使用此代码创建了一个新的空白应用程序,它与 apk 配合良好。有人可以帮助我吗?

这是我的配置.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>
您需要将

"允许意图"元添加到您的配置中.xml

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

您需要将内容-安全-策略元添加到索引中.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 插件。

最新更新