【问题标题】:The same URL of a Java script is different from different pages同一个Java脚本的URL不同的页面是不同的
【发布时间】:2021-11-24 22:55:56
【问题描述】:

我正在尝试使用 THREE.Js 加载资源

function loadScene(scene) {
            var loader = new THREE.ObjectLoader();
            loader.load("..//scenes//IR.json",
                function (obj) {
                    scene.add(obj);
                },
                function (x) {
                    console.log(x.loaded / x.total * 100 + '%')
                },
                function (err) {
                    console.log('Error: died.')
                }
            );
            return scene;
        }

我在两个不同的视图上使用相同的脚本。 在一个视图中一切正常,在另一个视图中我得到一个不同的 URL。

工作请求网址: https://localhost:44351//scenes//IR.json

第二个请求网址: https://localhost:44351/Funtiongroup//scenes//IR.json

每次在视图中调用相同的脚本。

“Funtiongroup”是这个视图的控制器。

【问题讨论】:

    标签: asp.net url three.js


    【解决方案1】:

    您已指定脚本文件的相对路径。该路径是相对于当前页面的 URL 解析的。

    如果您加载了https://localhost:44351/Home/,那么您的相对路径将解析为https://localhost:44351//scenes//IR.json

    如果您加载了https://localhost:44351/Functiongroup/Index/,那么您的相对路径将解析为https://localhost:44351/Functiongroup//scenes//IR.json

    要从站点的根目录进行解析,请将.. 放在路径的开头:

    loader.load("/scenes/IR.json",
    

    注意:路径中不需要双正斜杠,除非您使用的是非常不寻常的网络服务器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 2016-07-24
      • 1970-01-01
      • 2018-02-10
      • 1970-01-01
      • 2013-06-09
      • 2013-12-25
      相关资源
      最近更新 更多