PhoneGap apk没有执行POST动作

时间:2017-01-17 14:36:27

标签: android cordova

在我的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一起运行良好。有人可以帮帮我吗?

这是我的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>

1 个答案:

答案 0 :(得分:0)

您需要添加&#34; allow-intent&#34; metas到你的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插件。