这是元的实际代码:
<meta http-equiv="Content-Security-Policy" content="connect-src 'self' data: gap: https://ssl.gstatic.com ; style-src 'self' 'unsafe-inline'; media-src *">
我正在开发cordova中的Android应用程序。我正在尝试从照片中的划痕URL中检索数据。这是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();
我现在只想在控制台中显示检索到的数据。
答案 0 :(得分:2)
内容安全政策将connect-src
限制为self
,data:
,gap:
(这是科尔多瓦的事情吗?)和https://ssl.gstatic.com
- 这个表示任何从URL中加载资源的尝试都将被阻止。
由于脚本尝试从http://uiiuh
加载JSON数据,因此它被阻止;您需要将http://uiiuh
添加到CSP规则中允许的来源列表中。