我正在尝试使用Ace代码编辑库(http://ace.ajax.org/),但遇到了麻烦。根据嵌入指南,这应该会从Amazons CDN加载所需的js文件。
<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
然而,它失败了,在Chromes控制台中它显示:
Could not load worker ace.js:1
DOMException {message: "SecurityError: DOM Exception 18", name: "SecurityError", code: 18, stack: "Error: An attempt was made to break through the se…cloudfront.net/src-min-noconflict/ace.js:1:76296)", INDEX_SIZE_ERR: 1…}
ace.js:1
我还尝试将ace库src-min文件夹放在本地,并使用
<script src="/js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
它也失败了,错误如下:
Uncaught RangeError: Maximum call stack size exceeded
GET http://mysite/mode-javascript.js 404 (Not Found) 123f2c9_ace_1.js:1
GET http://mysite/notes/theme-monokai.js 404 (Not Found) 123f2c9_ace_1.js:1
Uncaught RangeError: Maximum call stack size exceeded
最后,我尝试加载ace src-min文件夹中的所有js资源,同样失败,出现错误:S
发布于 2013-10-02 15:52:02
当我试图完成这件事时,我遇到了麻烦。ACE主页上给出的代码对我不起作用。我把我所有的文件都放在本地目录下,但如果你愿意,你也可以使用CDN。
我把lib/ace
中的ace目录放到了我的static/
目录中。将该部分更改为您自己的位置。
我不得不使用Require.js api来加载ace。这是为我工作的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>ACE in Action</title>
<style type="text/css" media="screen">
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<div id="editor">
function foo(items) {
var x = "All this is syntax highlighted";
return x;
}
</div>
<script type="text/javascript" src="/static/require.js"></script>
<script>
require.config({
baseUrl: window.location.protocol + "//" + window.location.host
+ window.location.pathname.split("/").slice(0, -1).join("/"),
paths: {
ace: "/static/ace"
}
});
require(["ace/ace"], function (ace) {
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
});
</script>
</body>
</html>
来源:https://github.com/ajaxorg/ace/issues/1017
如果你收到一些疯狂的错误,请查看此页面:http://requirejs.org/docs/errors.html
发布于 2013-04-01 02:17:32
我知道这不能准确地回答你的问题,但我写这篇文章是为了那些在这个页面上遇到同样问题的人
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Credentials: "true"
</IfModule>
或
editor.getSession().setUseWorker(false);
不工作。
我在Chrome上也遇到了同样的问题。我在Firefox和Opera中测试了我的网站,它按照预期工作。加载页面时,我一直收到Uncaught RangeError: Maximum call stack size exceeded
错误。
解决方案是清空Chrome的缓存,然后它又起作用了。即使是control/command + shift + r
或control + F5
也不能工作。我真的不得不进入设置并清空缓存。
再说一次,我知道这只是部分相关,但这是给其他登陆这个页面的人!
https://stackoverflow.com/questions/15599597
复制相似问题