2016-09-16 72 views
-1

的這是我的控制檯錯誤:
this is the error in my console拒絕連接到URL,因爲違反了內容安全策略

這是元的實際代碼:

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

我正在開發一個科爾多瓦的android應用程序。我正在嘗試從照片中的劃痕網址中檢索數據。這是的index.html

html> 
<head> 
<body> 


     <div role="main" class="ui-content"> 
      <div class="app"> 
     <h1>Apache Cordova</h1> 
     <div id="deviceready" class="blink"> 
      <p class="event listening">Connecting to Device</p> 
      <p class="event received">Device is Ready</p> 
     </div> 
    </div> 

,這是index.js

var app = { 
// Application Constructor 
initialize: function() { 
    this.bindEvents(); 
}, 
// Bind Event Listeners 
// 
// Bind any events that are required on startup. Common events are: 
// 'load', 'deviceready', 'offline', and 'online'. 
bindEvents: function() { 
    document.addEventListener('deviceready', this.onDeviceReady, false); 
     document.addEventListener('loadcities', this.onDeviceReady, false); 
}, 
// deviceready Event Handler 
// 
// The scope of 'this' is the event. In order to call the 'receivedEvent' 
// function, we must explicitly call 'app.receivedEvent(...);' 
onDeviceReady: function() { 
    app.receivedEvent('deviceready'); 
    app.receivedEvent('loadcities'); 
}, 

// Update DOM on a Received Event 
receivedEvent: function(id) { 
    if (id === 'deviceready') { 
    var parentElement = document.getElementById(id); 
    var listeningElement = parentElement.querySelector('.listening'); 
    var receivedElement = parentElement.querySelector('.received'); 

    listeningElement.setAttribute('style', 'display:none;'); 
    receivedElement.setAttribute('style', 'display:block;'); 

    console.log('Received Event: ' + id);} 
    else if (id === 'loadcities') { 
     var url = "http://uiiuh" 
     $.getJSON(url).done(function(response){ 
        if(!response.length){ 
         console.warn("Empty list of cities"); 
        } 
        config.cities = response; 
        $('body').trigger('city-data'); 
       }).fail(function(data, status, error){ 
        console.error("Something went wrong retrieving the cities via API") 
       }); 
     } 

    } 

}; 

app.initialize();

我想僅在控制檯中顯示檢索到的數據。

+1

可能的重複http://stackoverflow.com/questions/31211359/refused-to-load-the-script-because-it-violates-the-following-content-security-po 添加更多你的細節'試着去做:你在開發什麼?網站? Android應用程序?使用節點?科爾多瓦? 顯示一些代碼(更多),我們只是不知道你在說什麼。只有一個元標記不足以理解您的問題。 – Aethyn

+1

你實際上沒有說明你的問題是什麼。 – Makyen

+0

你是否正在追加使這個'http'調用到託管頁面的腳本? – Reyraa

回答

1

的內容安全,政策限制connect-srcselfdata:gap:(是,科爾多瓦的事情嗎?),並https://ssl.gstatic.com - 這意味着在從URL裝入一個資源的任何企圖不匹配的這一個將被阻止。

由於腳本嘗試從http://uiiuh加載JSON數據,因此它被阻止;您需要將http://uiiuh添加到CSP規則中允許的來源列表。

相關問題