Cordova 8.0.0 Ajax错误

时间:2018-03-08 10:36:08

标签: android ajax cordova

我知道,有关于此的更多主题,我通过了它们,但没有任何效果,所以这就是我写新内容的原因:

我正在尝试在Android平台上创建AJAX读取请求(但也计划推出iOS)。 每次尝试都会出现一些错误。

我做了什么:

1)我安装了cordova whitelist插件(附带cordova安装)

2)我在config.xml中有各种定义,每种类型的最后定义(访问,允许意图,允许导航)都设置为*用于测试目的

3)我(我认为)所有允许访问定义\ platforms \ android \ app \ src \ main \ AndroidManifest.xml

4)我尝试了各种html元标记

5)我尝试过removeig并重新添加android平台

6)我试图重启移动设备

7)我尝试过移动数据,wifi,甚至两者都是

8) ajax请求超过http,而不是https

9) ajax请求位于$(document).ready(...)

中的链接testAjax.js中

关于theese meta标签:

 <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' *">

得到 enter image description here

<!-- This policy allows everything (eg CSS, AJAX, object, frame, media, etc) except that 
    * CSS only from the same origin and inline styles,
    * scripts only from the same origin and inline styles, and eval()
-->
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

与上面相同。

<!-- Good default declaration:
    * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
    * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
    * Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
        * Enable inline JS: add 'unsafe-inline' to default-src
        * Enable eval(): add 'unsafe-eval' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline' 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *">

enter image description here

<meta http-equiv="Content-Security-Policy" content="default-src 'self' http://mytestdomain.com data: gap: https://ssl.gstatic.com 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *">

enter image description here

我尝试了很多,但总有一个是3个错误

另外,这是我的config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.TG.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>TG</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="http://mytestdomain.com" />
    <access origin="http://mytestdomain.com/*" />
    <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:*" />
    <allow-intent href="gap:*" />
    <allow-intent href="*" />
    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    <allow-navigation href="data:*" />
    <allow-navigation href="http://mytestdomain.com" />
    <allow-navigation href="*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-googlemaps" spec="^2.2.5">
        <variable name="API_KEY_FOR_ANDROID" value="mykey" />
        <variable name="API_KEY_FOR_IOS" value="mykey" />
        <variable name="PLAY_SERVICES_VERSION" value="11.8.0" />
        <variable name="ANDROID_SUPPORT_V4_VERSION" value="24.1.0" />
    </plugin>
    <preference name="Orientation" value="portrait" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <engine name="browser" spec="^5.0.3" />
    <engine name="android" spec="^7.0.0" />
</widget>

在Android清单中我有

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

所以任何想法,这里有什么问题以及如何让它发挥作用? (即使一切都是开放的,安全性不是问题,我只需要让它以任何方式工作)

提前致谢:)

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案。 关键是要删除&#34; self&#34; default-src中的关键字。 所以这有效:

 <meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline' 'unsafe-eval' *">

希望他们能尽快更新cordova文档,因为这没有涵盖并且遵循他们建议的所有元标记,就像在StackOverflow上的所有指南一样导致失败,因为每个人都有&#34; self&#34;那里有关键字。