没有白名单的Cordova AJAX请求

时间:2015-08-16 02:56:25

标签: ajax cordova request whitelist

我一直试图提出ajax请求

$.ajax({
    type: "GET",
    dataType: "json",
    url: "http://testing.com/ws/check?" + outputData,
    success: onSuccess,
    error: onError
});

但它失败了404错误,经过长时间的搜索后我发现我错过了白名单插件,但是从我搜索的白名单只是针对Android 4+和IOS 4+,Windows会工作吗?和黑莓? 有没有办法在不添加白名单的情况下执行此操作?

如果真的需要白名单,为什么会给我这个错误?

Refused to apply inline style because it violates the following Content Security Policy directive: "default-src 'self' https:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'style-src' was not explicitly set, so 'default-src' is used as a fallback.

我的HTML:

<!-- CSP support mode (required for Windows Universal apps): https://docs.angularjs.org/api/ng/directive/ngCsp -->
<html lang="en" ng-app="app" ng-csp>
<head>
    <!-- Setting environment up -->
        <meta charset="utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="mobile-web-app-capable" content="yes" />
        <meta name='viewport' content='width=device-width, maximum-scale=1.0, user-scalable=no, target-densityDpi=device-dpi'>
    <!--  -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *">
    <!-- Enable all requests, 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'">
    <!-- Allow XHRs via https only -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' https:">
    <!-- Allow iframe to https://cordova.apache.org/ -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src 'self' https://cordova.apache.org">
    <!-- JS dependencies (order matters!) -->
        <script src="scripts/platformOverrides.js"></script>
        <script src="lib/angular/angular.js"></script>
        <script src="lib/jquery/jquery-1.11.3.min.js"></script>
        <script src="lib/onsen/js/onsenui.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
    <!--  -->
    <!-- CSS dependencies -->
        <link rel="stylesheet" href="lib/onsen/css/onsenui.css" />
        <link rel="stylesheet" href="lib/onsen/css/onsen-css-components-blue-basic-theme.css" />
    <!--  -->
    <!-- CSP support mode (required for Windows Universal apps) -->
        <link rel="stylesheet" href="lib/angular/angular-csp.css" />
    <!--  -->
    <!-- --------------- App init --------------- -->
    <script src="js/app.js"></script>
        <script src="js/Pages/SplashScreen.js"></script>
        <script src="js/utils.js"></script>
        <link rel="stylesheet" href="css/app.css" />
    <!--  -->
    <!-- Application Title -->
        <title>Testing</title>
    <!--  -->
    </head>
    <body ng-controller="AppController">
    <!-- Cordova reference -->
    <script src="scripts/index.js"></script>
    <!-- -->
    <!-- Navigator! Everything runs inside it! -->
    <ons-navigator var="navi">
    </ons-navigator>
    <!-- -->
    <!-- Templates -->
        <!-- Splashscreen -->
        <ons-template id="splashScreen.html" style="background:none">
            <ons-page id="splashScreen" ng-controller="SplashScreenController">
                <div id="splashScreen2" class="background_image">
                    <img id="background-image" width="100%" height="100%">
                </div>
            </ons-page>
        </ons-template>
        <!-- --> 
    <div id="result"/>
</body>
</html>

谢谢你, 若昂

1 个答案:

答案 0 :(得分:0)

首先你应该安装Cordova白名单插件(我想你已经有了)。 然后将以下内容添加到config.xml目录中的platforms/<platform name>/res/xml文件中。

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