如何在服务器中为我的Firefox OS应用程序加载远程内容-在Web和FxOS设备中
How to load remote content in server for my Firefox OS app - In Web and FxOS device
我在论坛中没有发现这个问题,所以我写了这个。
当我从服务器上获取远程内容时,我的FirefoxOS设备(Geekspophone开发者预览版)中的FirefoxOS应用程序出现问题。
从我的JS文件开始,我就用AJAX调用服务器中的PHP文件,它会在我的HTML文件中打印contentResult。这是正确的。
这是javascript文件内容
window.addEventListener('DOMContentLoaded', function() {
'use strict';
var translate = navigator.mozL10n.get;
navigator.mozL10n.once(start);
function start() {
var message = document.getElementById('message');
message.textContent = translate('message');
show_content();
}
document.getElementById("btn_1").addEventListener("click",function(){
console.log("hola mundo");
alert("hola mundo");
});
document.getElementById("btn_2").addEventListener("click",function(){
console.log("adios mundo");
alert("adios mundo");
});
function show_content(){
var xmlhttp = new XMLHttpRequest();
var url = server_path + "ejemplo.php";
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txt_server").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send();
}
});
function aviso(){
console.log("clicked");
alert("clicked");
}
这是HTML文件内容
<html>
<head>
<meta charset="utf-8">
<title>Example 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" defer></script>
<link rel="prefetch" type="application/l10n" href="data/locales.ini" />
<script type="text/javascript" src="js/libs/l10n.js" defer></script>
</head>
<body>
<section>
<h1 data-l10n-id="app_title">My example app</h1>
<p data-l10n-id="app_description">With this example, I want to show a button loaded in HTML and then load content from server by XMLHttpRequest. Two buttons will have click function developed, with alert and console message.</p>
<p id="message"></p>
<button class="wide" data-l10n-id="btn_1" id="btn_1">Click me 1</button>
<button class="wide" data-l10n-id="btn_2" id="btn_2" hidden></button>
<p><span id="txt_server"></span></p>
</section>
</body>
</html>
这是PHP文件内容
<?php
//to solve CORS advice
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With,Content-Type, Accept");
header("Content-Type: text/html;charset=utf-8");
echo "<button class='"wide'" data-l10n-id='"btn_2'" id='"btn_2'">Click me 2</button><br/>";
echo "<a onclick='"aviso();'" class='"wide'">Click me 3</a>";
?>
所以,问题是:
- 当我调用PHP文件时,通常创建的按钮没有可点击的功能,在web和FxOS应用程序中都没有
- "a"元素也是在对PHP文件的调用中创建的,在它有可点击的功能[显示警报和日志],但在应用程序中安装在FxOS设备中,它什么都不做
在这个链接中,你可以测试我试图向你解释的内容。如果你想查看代码,有一个zip文件。zip文件
谢谢你抽出时间。如果你不明白什么,问我。
听起来像是违反了CSP(https://developer.mozilla.org/en-US/Apps/Build/Building_apps_for_Firefox_OS/CSP)你不能用onclick。
这是根据CORS规范第7.3节:设计的
- 由于证书错误,不允许使用https
使用自签名证书被视为证书错误。尝试使用systemXHR客户端,而不是CORS服务器端。
相关文章:
- 在chrome web商店中打开时,是否有允许执行内容/后台脚本的解决方案
- 使用下拉菜单筛选Web内容
- 如何在服务器中为我的Firefox OS应用程序加载远程内容-在Web和FxOS设备中
- JavaScript窗口.位置不;我不在内容编辑器Web部件中工作
- 使用PhantomJS下载动态web内容时遇到问题
- 追加新web组件时出现线程问题
- 从客户端 Web 应用程序中提取 Excel 内容
- Web 工作线程中的同步 XHR 请求是否仍会锁定浏览器
- 在Asp.net的空网站中,如何改变"Web.config”;使内容(.js)文件显示在浏览器中,而不是下载
- 使用JSONP内容压缩web服务响应是否有效
- 在Firefox中与Web内容(页面对象)共享插件对象(内容脚本)
- 如何在FileMaker Web Viewer中从网站检索内容
- 强制web浏览器下载整个页面内容
- 用程序更改Electron中Web视图的内容
- 谷歌'soa架构-为谷歌聚合内容'的web用户界面
- 将web标记为过时,以强制浏览器重新加载其内容
- 托管时,angular.js web应用程序中未显示内容
- 如何从本地html文件获取web服务器's内容
- 如何使用Javascript获取web url内容
- 如何使用minibuffer为react js文件设置web模式内容类型