firefox OS内容安全策略错误,基于XHR的应用程序在Index.html
firefox OS Content Security Policy error XHR based application in Index.html?
控制台出现此错误。
内容安全策略:该页面的设置阻止了在self加载资源("script-src app://fa91d835-176d-4fe7-bd06-fe7f57f11b68")。
我尝试创建一个firefox ajax应用程序来从我的编码器控制器检索一些数据。当我检查控制台时,它只返回错误。我只在文件外添加了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);
}
};
}
请帮帮我!
你不能使用属性onclick=''
,因为它违反了CSP
因为你使用的是jquery,所以把它添加到xhrap .js
$(document).ready(function(){
$("#mybutton").on("click", xhrapp);
});
把你的HTML改成:
<button id="mybutton">Click</button> <!-- <a> is not needed -->
查看更多信息: https://developer.mozilla.org/en-US/Apps/Build/Building_apps_for_Firefox_OS/CSP
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- Emberjs应用程序加载在除Index之外的所有路由上
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- angular 1.5应用程序中的导航栏
- 在Web应用程序中使用Highcharts javascript
- angularjs+rails应用程序中未显示模板
- 使用acess代币登录Facebook,并通过网络应用程序离线发布
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 科尔多瓦页面类应用程序中的多个谷歌地图
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- XHR不适用于聊天应用程序
- Windows商店应用程序JS:使用WinJS.xhr上传视频文件
- Windows 应用商店应用程序 xhr 到 localhost 失败
- 如果应用程序具有 XHR 调用,其中应用程序/json 作为“类型”,是否意味着它是 AJAX
- rails应用程序中的AJAX请求错误:xhr.send((options.hasContent&&op
- firefox OS内容安全策略错误,基于XHR的应用程序在Index.html
- 无法从使用node.js的电子应用程序使用xhr从文件系统上传1GB的文件(硬编码文件,不使用输入类型文件)