AJAX 使用 Cordova Android 失败

AJAX failing in Android using Cordova

我一直在努力对我的 node.js 服务器进行 AJAX 调用,但没有成功。

我做了以下事情:

1) 在我的 node.js 服务器中安装了 cors 包。 AJAX 确实在浏览器中工作。

2) 向 index.html 添加了以下内容安全策略:

<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://maps.googleapis.com https://163.172.175.135">

3) 在我的 config.xml:

中添加了几行
<?xml version='1.0' encoding='utf-8'?>
<widget id="roda.X.XXXX" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Roda</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <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>
    <engine name="android" spec="^6.2.3" />
    <engine name="browser" spec="^4.1.0" />
    <plugin name="cordova-plugin-geolocation" spec="^2.4.3" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
</widget>

我错过了什么?

我后来发现 AJAX 可以在调试模式下工作,但不能在发布模式下工作。问题是我使用 IP 地址而不是域名连接到服务器,因此无法通过 SSL 验证。在调试模式下,不验证 SSL 证书。

呸。问题已解决!