我在控制台上发现了这个错误。
内容安全策略:页面设置阻止了self上的资源加载("script-src app://fa91d835-176 d-4fe7-bd06-fe7f57f11b68“)。
我尝试创建一个firefox应用程序,从我的代码点火器控制器中检索一些数据。当我检查控制台时,它只返回错误。我只在文件之外添加了javascript函数。但它说CSP错误。
我的Index.Html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Privileged app</title>
<meta name="description" content="A privileged app stub">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/app.css">
<script type="text/javascript" src="js/app.js" ></script>
<script type="text/javascript" src="js/jquery-1.7.1.min.js" ></script>
<script type="text/javascript" src="js/xhrapp.js" ></script>
<link rel="prefetch" type="application/l10n" href="data/locales.ini" />
<script type="text/javascript" src="js/libs/l10n.js" ></script>
</head>
<body>
<section>
<h1 data-l10n-id="app_title">Privileged empty app</h1>
<p data-l10n-id="app_description">This app is empty. Fill it with your own stuff!</p>
<p id="message"></p>
<input type="text" id="ajax_data" value="">
<a href="" onclick="xhrapp();"><button>Click</button></a>
</section>
</body>
</html>函数xhrapp.js
function xhrapp(){
var a=$("#ajax_data").val();
alert(a);
console.log("in function");
var xhr = new XMLHttpRequest({
mozSystem: true
});
// xhr.open("POST", "http://blac.byethost7.com/home/index.php/welcome/demo");
xhr.open("POST", "http://localhost/shop/home/home/demo");
xhr.send(a);
xhr.onload = function() {
if (xhr.status == 200) {
console.log(xhr.responseText);
// alert(xhr.responseText);
}
};
}请帮帮我!
发布于 2015-09-29 11:44:08
您不能使用属性onclick='',因为它违反了CSP
由于您正在使用jquery,所以将其添加到xhrapp.js中。
$(document).ready(function(){
$("#mybutton").on("click", xhrapp);
});将HTML更改为:
<button id="mybutton">Click</button> <!-- <a> is not needed -->查询更多信息,请查看: OS/CSP
https://stackoverflow.com/questions/32836348
复制相似问题