javascript 无法从网络驱动器运行

标签 javascript jquery ajax node.js jquery-ui

我正在尝试运行以下文件。当我在本地驱动器上运行它时,它运行得很好,但如果我将它放在网络驱动器上,它就不再工作。知道为什么会这样吗?

下面是我尝试运行的代码。它使用这里的数据透视表:https://github.com/nicolaskruchten/pivottable

<!DOCTYPE html>
<html>
<head>
    <title> Demo</title>
    <!-- external libs from cdnjs -->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

    <!-- PivotTable.js libs from ../dist -->
    <link rel="stylesheet" type="text/css" href="../dist/pivot.css">
    <script type="text/javascript" src="../dist/pivot.js"></script>
    <style>
        body {font-family: Verdana;}
    </style>

    <!-- optional: mobile support with jqueryui-touch-punch -->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>



</head>
<body>
    <script type="text/javascript">
// This example shows custom aggregators using 


$(function(){
    var tpl = $.pivotUtilities.aggregatorTemplates;

    $.getJSON("col.json", function(frontier) {
        $("#output").pivotUI(frontier, {
            rows: ["Manager"], cols: ["Sector"],
            aggregators: {
                "Number of Positions":      function() { return tpl.count()() },
                "Manager Weight": function() { return tpl.sum()(["Port"])},
                "Benchmark XGCC Weight": function() { return tpl.sum()(["Bench"])},
            }
        });
    });
 });
    </script>



    <div id="output" style="margin: 30px;"></div>

</body>
</html>

最佳答案

File:/// url 将在与 HTTP/HTTPS 和其他上下文(内部、公共(public)、私有(private)、不安全)不同的上下文中运行。所讨论的限制取决于特定的浏览器、操作系统和上下文本身。

如果您必须在 HTML 中执行 JavaScript,最安全、最可靠的运行方式是通过 Web 服务器运行它。

<小时/>

还值得注意的是,有一些本地/相对文件。 ../dist/pivot.js../dist/pivot.css 您确定要保存这些文件,并且它们也位于正确的相对路径中吗?

关于javascript 无法从网络驱动器运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39460872/

相关文章:

jquery - 小部件 CSS 与站点 CSS 冲突

javascript - node.js - 向所有连接的广播消息

javascript - 在 noconflict 中加载似乎不起作用

javascript - document.documentElement.clientHeight 和 document.body.clientHeight 的区别

javascript - 在 Javascript 中获取没有模 (%) 运算符的余数,占 -/+ 符号

php - jQuery AJAX 表单不发布结果

php - 使用 AJAX 发送两个变量(我有一个正在工作,但需要两个)

javascript - 如果值标签是某物,则添加 html

javascript - 2 div 由于滚动条而偏移

javascript - jQuery 以纯文本形式获取 div 的绿色背景(获取 "green",而不是 "rgb(0,128,0)",而不是 "#0f0")