html 页面在本地有效,但在云端无效 ide
html page works when local but not when on cloud ide
我正在尝试在一个简单的网页上呈现一个 d3.js 图表。该图非常简单。我 运行 它来自 cloud9,它通常是基于 IDE 的非常好的无错误云。然而,当我 运行 它的页面是空白的。我可以得到简单的 javascript 函数来渲染,但是(警报和 "hello world" 等)但不是 d3.js。我不确定为什么。所以我 运行 cloud9 中的 html 然后从浏览器中执行 'view source' 并将代码逐字复制粘贴到我 mac 笔记本电脑上的本地 html 页面运行 它,它运行良好。所以基本上我不明白为什么它在 cloud9 上不起作用。这是代码原样..
<!DOCTYPE html>
<html>
<head>
<title>TBB</title>
<link data-turbolinks-track="true" href="/assets/style.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/example.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/user.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="5jRBVsv8vrjFDZO2I0dCoMt95++mzwENzkS+eP9ijAU=" name="csrf-token" />
<style>
.node {
fill: #ccc;
stroke: #fff;
stroke-width: 2px;
}
.link {
stroke: #777;
stroke-width: 2px;
}
</style>
</head>
<body>
<script src='http://d3js.org/d3.v3.min.js'></script>
<script>
var width = 640,
height = 480;
var nodes = [
{ x: width/3, y: height/2 },
{ x: 2*width/3, y: height/2 }
];
var links = [
{ source: 0, target: 1 }
];
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
var force = d3.layout.force()
.size([width, height])
.nodes(nodes)
.links(links);
force.linkDistance(width/2);
var link = svg.selectAll('.link')
.data(links)
.enter().append('line')
.attr('class', 'link');
var node = svg.selectAll('.node')
.data(nodes)
.enter().append('circle')
.attr('class', 'node');
force.on('end', function() {
node.attr('r', width/25)
.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; });
link.attr('x1', function(d) { return d.source.x; })
.attr('y1', function(d) { return d.source.y; })
.attr('x2', function(d) { return d.target.x; })
.attr('y2', function(d) { return d.target.y; });
});
force.start();
</script>
</body>
</html>
您有两次以下情况:
</head>
<body>
所以 HTML 无效。
我刚刚在云 9 中尝试过。当我 运行 html 文件时,它给了我一个 https
link。 Chrome 正确地抱怨在安全页面上加载非安全资源:
Mixed Content: The page at 'https://demo-project-larsenmtl.c9.io/html/index.html' was loaded over HTTPS, but requested an insecure script 'http://d3js.org/d3.v3.min.js'. This request has been blocked; the content must be served over HTTPS.
index.html:38 Uncaught ReferenceError: d3 is not defined
用 http
试试你的 link 或从支持 https
的 cdn 加载 d3,比如 cloudflare:
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js
我正在尝试在一个简单的网页上呈现一个 d3.js 图表。该图非常简单。我 运行 它来自 cloud9,它通常是基于 IDE 的非常好的无错误云。然而,当我 运行 它的页面是空白的。我可以得到简单的 javascript 函数来渲染,但是(警报和 "hello world" 等)但不是 d3.js。我不确定为什么。所以我 运行 cloud9 中的 html 然后从浏览器中执行 'view source' 并将代码逐字复制粘贴到我 mac 笔记本电脑上的本地 html 页面运行 它,它运行良好。所以基本上我不明白为什么它在 cloud9 上不起作用。这是代码原样..
<!DOCTYPE html>
<html>
<head>
<title>TBB</title>
<link data-turbolinks-track="true" href="/assets/style.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/example.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/user.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/application.js?body=1"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="5jRBVsv8vrjFDZO2I0dCoMt95++mzwENzkS+eP9ijAU=" name="csrf-token" />
<style>
.node {
fill: #ccc;
stroke: #fff;
stroke-width: 2px;
}
.link {
stroke: #777;
stroke-width: 2px;
}
</style>
</head>
<body>
<script src='http://d3js.org/d3.v3.min.js'></script>
<script>
var width = 640,
height = 480;
var nodes = [
{ x: width/3, y: height/2 },
{ x: 2*width/3, y: height/2 }
];
var links = [
{ source: 0, target: 1 }
];
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height);
var force = d3.layout.force()
.size([width, height])
.nodes(nodes)
.links(links);
force.linkDistance(width/2);
var link = svg.selectAll('.link')
.data(links)
.enter().append('line')
.attr('class', 'link');
var node = svg.selectAll('.node')
.data(nodes)
.enter().append('circle')
.attr('class', 'node');
force.on('end', function() {
node.attr('r', width/25)
.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; });
link.attr('x1', function(d) { return d.source.x; })
.attr('y1', function(d) { return d.source.y; })
.attr('x2', function(d) { return d.target.x; })
.attr('y2', function(d) { return d.target.y; });
});
force.start();
</script>
</body>
</html>
您有两次以下情况:
</head>
<body>
所以 HTML 无效。
我刚刚在云 9 中尝试过。当我 运行 html 文件时,它给了我一个 https
link。 Chrome 正确地抱怨在安全页面上加载非安全资源:
Mixed Content: The page at 'https://demo-project-larsenmtl.c9.io/html/index.html' was loaded over HTTPS, but requested an insecure script 'http://d3js.org/d3.v3.min.js'. This request has been blocked; the content must be served over HTTPS.
index.html:38 Uncaught ReferenceError: d3 is not defined
用 http
试试你的 link 或从支持 https
的 cdn 加载 d3,比如 cloudflare:
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js