为什么 Dijit 不适合我?

发布于 2025-01-07 18:42:14 字数 1731 浏览 0 评论 0原文

代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/resources/dojo.css"> 
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/themes/claro/claro.css">

    <script type="text/javascript">
        dojo.require("dijit.layout.AccordionContainer");
    </script>

    <script type="text/css">
        html, body {
            width: 100%;
            height: 100%;
        }
    </script>
</head>

<body class='claro'>
    <div data-dojo-type="dijit.layout.AccordionContainer" style="width: 200px; height: 95%; margin: 0 auto;">
        <div data-dojo-type="dijit.layout.AccordionPane" title="pane #1">accordion pane #1</div>
        <div data-dojo-type="dijit.layout.AccordionPane" title="pane #2">accordion pane #2</div>
        <div data-dojo-type="dijit.layout.AccordionPane" title="pane #3">accordion pane #3</div>
    </div>
</body>
</html>

这只是 Dojo 示例中的一段非常简单的代码。

当我在 Safari 中运行它时,除了一些纯文本之外什么都没有出现。

当我在 chrome 中运行它时,出现以下错误:

XMLHttpRequest cannot load http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/layout/AccordionContainer.js. Origin null is not allowed by Access-Control-Allow-Origin.

Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101              dojo.js:15

问题是什么

Here is the code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/resources/dojo.css"> 
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/themes/claro/claro.css">

    <script type="text/javascript">
        dojo.require("dijit.layout.AccordionContainer");
    </script>

    <script type="text/css">
        html, body {
            width: 100%;
            height: 100%;
        }
    </script>
</head>

<body class='claro'>
    <div data-dojo-type="dijit.layout.AccordionContainer" style="width: 200px; height: 95%; margin: 0 auto;">
        <div data-dojo-type="dijit.layout.AccordionPane" title="pane #1">accordion pane #1</div>
        <div data-dojo-type="dijit.layout.AccordionPane" title="pane #2">accordion pane #2</div>
        <div data-dojo-type="dijit.layout.AccordionPane" title="pane #3">accordion pane #3</div>
    </div>
</body>
</html>

It is just a very simple code from the example of Dojo.

When I run it in safari, nothing appears but some plain text.

When I run it in chrome, following error occurs:

XMLHttpRequest cannot load http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/layout/AccordionContainer.js. Origin null is not allowed by Access-Control-Allow-Origin.

and

Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101              dojo.js:15

What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨后咖啡店 2025-01-14 18:42:14

1.您忘记需要 dijit.layout.AccordionPane
2.您忘记调用解析器

尝试这个:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <script type="text/javascript">
            var dojoConfig = {
                                    async : true,
                                    parseOnLoad : true
                            }
        </script>
        <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/resources/dojo.css"> 
        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/themes/claro/claro.css">

        <script type="text/javascript">
            require(["dijit/layout/AccordionContainer", 
                     "dijit/layout/AccordionPane"], 
                     function(){
                          // your code...
                     }
            );
        </script>

        <script type="text/css">
            html, body {
                width: 100%;
                height: 100%;
            }
        </script>
    </head>

    <body class='claro'>
        <div data-dojo-type="dijit.layout.AccordionContainer" style="width: 200px; height: 95%; margin: 0 auto;">
            <div data-dojo-type="dijit.layout.AccordionPane" title="pane #1">accordion pane #1</div>
            <div data-dojo-type="dijit.layout.AccordionPane" title="pane #2">accordion pane #2</div>
            <div data-dojo-type="dijit.layout.AccordionPane" title="pane #3">accordion pane #3</div>
        </div>
    </body>
</html>

或者,您可以通过将 data-dojo-config="parseOnLoad: true" 添加到加载 dojo.js 的脚本标记来在页面加载时调用它,而不是手动调用解析器,或者通过在加载 dojo.js 之前设置变量 dojoConfig (参见 http://dojotoolkit.org/documentation/tutorials/1.7/dojo_config/)。

1.You forgot to require dijit.layout.AccordionPane
2. You forgot to invoke the parser

Try this :

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <script type="text/javascript">
            var dojoConfig = {
                                    async : true,
                                    parseOnLoad : true
                            }
        </script>
        <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/resources/dojo.css"> 
        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/themes/claro/claro.css">

        <script type="text/javascript">
            require(["dijit/layout/AccordionContainer", 
                     "dijit/layout/AccordionPane"], 
                     function(){
                          // your code...
                     }
            );
        </script>

        <script type="text/css">
            html, body {
                width: 100%;
                height: 100%;
            }
        </script>
    </head>

    <body class='claro'>
        <div data-dojo-type="dijit.layout.AccordionContainer" style="width: 200px; height: 95%; margin: 0 auto;">
            <div data-dojo-type="dijit.layout.AccordionPane" title="pane #1">accordion pane #1</div>
            <div data-dojo-type="dijit.layout.AccordionPane" title="pane #2">accordion pane #2</div>
            <div data-dojo-type="dijit.layout.AccordionPane" title="pane #3">accordion pane #3</div>
        </div>
    </body>
</html>

Alternatively, instead of invoking the parser manually, you may invoke it on page load by adding data-dojo-config="parseOnLoad: true" to the script tag where dojo.js is loaded, or by setting the variable dojoConfig before dojo.js is loaded (see http://dojotoolkit.org/documentation/tutorials/1.7/dojo_config/).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文