gpt4 book ai didi

javascript - 由于违反内容安全策略而拒绝连接到 URL

转载 作者:行者123 更新时间:2023-12-02 14:11:29 26 4
gpt4 key购买 nike

这是我的控制台中的错误:
this is the error in my console

这是元的实际代码:

<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 *">

我正在 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();

我现在只想在控制台中显示检索到的数据。

最佳答案

内容安全策略限制connect-srcselfdata:gap:(这是 Cordova 的东西吗?)和 https://ssl.gstatic。 com — 这意味着从与其中之一不匹配的 URL 加载资源的任何尝试都将被阻止。

由于脚本尝试从 http://uiiuh 加载 JSON 数据,因此被阻止;您需要将 http://uiiuh 添加到 CSP 规则中允许的源列表中。

关于javascript - 由于违反内容安全策略而拒绝连接到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39527150/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com