ajax.post在Android设备上不起作用

时间:2017-12-29 14:25:37

标签: android cordova phonegap

ajax.post在浏览器中运行良好,但在真正的Android设备上不起作用(我不知道如何看到错误,因为我已离开浏览器环境)。 我认为我有互联网许可或原产地限制的问题。我已经阅读了ManifestAndroid.xml但我在我的项目中找不到它。(没有这样的文件)

我该如何解决这个问题?提前致谢

这是我的config.xml:

 <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>

这是index.html限制:

<access origin="http://example.com" />


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

1 个答案:

答案 0 :(得分:0)

我的Angular 2应用程序遇到了这个问题,我所做的事情如下:

1)当您加载Android Studio时,您可以选择File->Profile APK来调试/运行APK,然后您可以查看logcat以查看任何错误消息。

2)添加allow-navigation tag in config.xml
您需要将Whitelist plugin添加到plugin section of the config

3)您提出请求的URL是什么?我的大问题是我使用的是相对URL,因为我的Web App在设备而不是服务器上,我的相对路径指向文件协议文件://不是http://。 所以我建议确保网址是绝对的,即http://,你的应用程序可能会对文件系统发帖,而不是它失败的原因