net :: ERR_NAME_NOT_RESOLVED在动态脚本加载时

时间:2018-10-22 07:18:27

标签: javascript

我试图在运行时(单击按钮)加载脚本(来自相同的源!),但是由于一个奇怪的原因,我在控制台中收到错误:net :: ERR_NAME_NOT_RESOLVED

示例在此链接中:https://www.crazygao.com/ef4/tst.htm

通过单击文本区域,将初始化一个调用以加载表单-尽管使用相同的动态脚本加载,但此调用由于某种奇怪的原因而成功。 单击“ +”以在组合框中添加项目时,将触发错误-请求的脚本将无法加载。

请注意我的通话方式:

// Call to external function in a script:
_.Run=function(p) {
    if(_.xT(p)=="S") p={f:p}; // If the call is string, it will convert it to function name
    if(!window[p.f]) { // If the function not exists in global scope, need to look for the JS file to request it.
        _.xR("/"+p.x||p.f,function() { _.Run(p); }); // Dynamic loader
    }
    else { window[p.f](p.v); } // Run the function
}

// Short hand for loading script on runtime:
_.xR=function(p,f,a) {
    var r=_.xM("script"); // I am creating new <script> tag
    _.xW(r,"charset","UTF-8"); // I set attribute "charset" to "UTF-8"
    r.src=p; // I set the source
    // "a" is not relevant for here - I cut it off
    document.head.appendChild(r); // I append to document head
}

// Short hand for creating new element and appending it to the DOM
_.xM=function(t,i,r,s,c,u) {
    t=document.createElement(t);
    if(t.nodeName=="IMG") t.ondragstart=function(e) { e.preventDefault(); }
    if(i) t.id=i;
    if(r) _.xI(r).insertBefore(t,u);
    /* Unnecessary data I cut off */
    return t;
}

// Short hand for getting element by ID
_.xI=function(e,c) {
    if(_.xT(e)=="S") e=document.getElementById(e); return (e||c)?e:document.body;
}

// Short hand for getting type of variable
_.xT=function(e) {
    if(e instanceof Array) return "A";
    if(e instanceof ML) return "L";
    if(e instanceof Date) return "D";
    if(e instanceof FF) return "F";
    if(e instanceof _.P) return "P";
    if(e instanceof _.C) return "C";
    if(e instanceof Image) return "I";
    if(typeof e==="number"&&!isNaN(e)) return "N";
    if(typeof e==="string") return "S";
    if(typeof e==="boolean") return "B";
    if(typeof e==="function") return "Q";
    return e?"O":null;
}

// Short hand for setting or removing attribute
_.xW=function(c,n,v,s) {
    return s?_.xW(c,n,_.xW(c,n,"~")?0:v):c[(v?(v=="~"?"get":"set"):"remove")+"Attribute"](n,v);
}

我认为“快捷方式”没有任何错误,因为它们适用于已加载的其他脚本(可以在示例链接中查看)。

在服务器中没有任何阻塞,因为相同的目录被相同的脚本读取并成功下载(在示例链接中:ML.js成功,Lang.js失败)

非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

是:问题的根本原因似乎不是缺少“ /”,而是重复前面的“ /”导致“ https:////ef4/Lang.js”->浏览器可能将此视为“ https://ef4/Lang.js”-因此是一个错误...

已解决的问题:)