簡體   English   中英

為什么瀏覽器會嘗試從服務器加載本地 JavaScript 文件?

[英]Why is the browser trying to load a local JavaScript file from a server?

我有一個簡單的 HTML 頁面,它試圖訪問遠程和本地 JavaScript 文件:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script src="https://js.arcgis.com/3.19/"></script>
    <script src="SearchExtent.js"></script>
    <script>
        require([
            ...

SearchExtent.js與 HTML 頁面存儲在同一文件夾中。

在 Chrome 和 Edge 中調試 HTML 頁面時,都會出現 404 錯誤,表示找不到以下資源:

https://js.arcgis.com/3.19/SearchExtent.js

為什么瀏覽器查看遠程服務而不是本地文件系統>

Dojo 必須正確配置才能使用本地和 CDN 源。 以下是從 CDN 和本地服務器正確加載內容的代碼:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://js.arcgis.com/3.19/esri/css/esri.css">
<script>
    var dojoConfig = {
        paths: { js: location.pathname.replace(/\/[^/]+$/, "") + "/js" }
    };
</script>
<script src="https://js.arcgis.com/3.19"></script>
<script>
    require([
        "js/SearchExtent",
        "dojo/domReady!"
    ], function (SearchExtent) {
        console.log("...");
    });
</script>
</head>
<body>
</body>
</html>

property of dojoConfig is used to specify the location of the "js" alias on the local server. dojoConfig 的屬性用於指定“js”別名在本地服務器上的位置。 另請注意,沒有對自定義 JavaScript 模塊的顯式引用。 references the custom module using the alias defined in the property.的調用使用在屬性中定義的別名來引用自定義模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM