【发布时间】:2015-08-02 17:52:02
【问题描述】:
我正在尝试使用跟踪器。但是,当我想加载一个模块时,我收到一个错误,指出它不成功。我的代码基于其关于模块的文档中提供的示例跟踪器。
这是main.html:
<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script>
System.traceurOptions = { experimental: true }
</script>
<script type="module" src="ProfileView.js"></script>
以及加载的模块:
// ProfileView.js
import {firstName, lastName, year} from './Profile.js';
function setHeader(element) {
element.textContent = firstName + ' ' + lastName;
}
// rest of module
// Profile.js
export var firstName = 'David';
export var lastName = 'Belle';
export var year = 1973;
我在 Chrome 中收到以下错误:
XMLHttpRequest 无法加载 file:///C:/Code/Tests/Traceur/ProfileView.js。跨源请求 仅支持协议方案:http、data、chrome、 铬扩展,https,铬扩展资源。
WebPageTranscoder 加载失败 file:///C:/Code/Tests/Traceur/ProfileView.js
未捕获的网络错误:无法在“XMLHttpRequest”上执行“发送”: 无法加载“file:///C:/Code/Tests/Traceur/ProfileView.js”。
我知道你不能通过文件系统发出 xhr 请求,但我看过一些教程,其中代码的结构与我的相似,并且可以在那里工作......
我可能做错了什么?
【问题讨论】:
-
那些教程可能希望在网络服务器上运行(即使是本地服务器)。
标签: javascript xmlhttprequest cross-domain traceur