javascript - 无法加载源:http://localhost/js/m.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2025445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:27:11  来源:igfitidea点击:

javascript - Failed to load source for: http://localhost/js/m.js

javascriptload

提问by n00b0101

Why oh why oh why... I can't figure out why I keep getting this error. I think I might cry.

为什么哦为什么哦为什么...我不明白为什么我一直收到这个错误。我想我可能会哭。

/*** common functions  */
function GE(id) { return document.getElementById(id); }

function changePage(newLoc) {
   nextPage = newLoc.options[newLoc.selectedIndex].value

   if (nextPage != "")
   {
      document.location.href = nextPage
   }
 }

function isHorizO(){
  if (navigator.userAgent.indexOf('iPod')>-1)
    return (window.orientation == 90 || window.orientation==-90)? 1 : 0;
   else   return 1;

}

function ShowHideE(el, act){
    if (GE(el)) GE(el).style.display = act;
}

function KeepTop(){
    window.scrollTo(0, 1);
}

/* end of common function */

var f = window.onload; 
if (typeof f == 'function'){
    window.onload = function() {
        f();
        init();
    }
}else window.onload = init;

function init(){
    if (GE('frontpage')) init_FP();
    else {
        if (GE('image')) init_Image();
        setTimeout('window.scrollTo(0, 1)', 100); 
     }

    AddExtLink();
}

function AddExtLink(){
    var z = GE('extLink');
    if (z){
        z = z.getElementsByTagName('a');
        if (z.length>0){
            z = z[0];
            var e_name = z.innerHTML;
            var e_link = z.href;

            var newOption, oSe;
            if (GE('PSel')) oSe = new Array(GE('PSel'));
            else
                oSe = getObjectsByClassName('PSel', 'select')

            for(i=0; i<oSe.length; i++){
                newOption = new Option(e_name, e_link);
                oSe[i].options[oSe[i].options.length] = newOption;
            }
        }
    }
}

/* fp */
function FP_OrientChanged() {
    init_FP();
}

function init_FP() {
  //  GE('orientMsg').style.visibility = (!isHorizO())? 'visible' : 'hidden';
}

/* gallery */
function GAL_OrientChanged(link){
    if (!isHorizO()){
        ShowHideE('vertCover', 'block');
        GoG(link);
    }
    setTimeout('window.scrollTo(0, 1)', 500);
}
function init_Portfolio() {
 //   if (!isHorizO())
 //       ShowHideE('vertCover', 'block');
}
function ShowPortfolios(){
    if (isHorizO()) ShowHideE('vertCover', 'none');
}

var CurPos_G = 1
function MoveG(dir) {
    MoveItem('G',CurPos_G, dir);
}

/* image */
function init_Image(){
    // check for alone vertical images
    PlaceAloneVertImages();
}
function Img_OrtChanged(){
    //CompareOrientation(arImgOrt[CurPos_I]);
    //setTimeout('window.scrollTo(0, 1)', 500);
}

var CurPos_I = 1
function MoveI(dir) {
    CompareOrientation(arImgOrt[CurPos_I+dir]);
    MoveItem('I',CurPos_I, dir);
}

var arImgOrt = new Array(); // orientation: 1-horizontal, 0-vertical
var aModeName = new Array('Horizontal' , 'Vertical');
var arHs = new Array();

function getDims(obj, ind){
    var arT = new Array(2);

    arT[0] = obj.height; 
    arT[1] = obj.width;


     //arWs[ind-1] = arT;
    arHs[ind] = arT[0];

     //**** (arT[0] > arT[1]) = (vertical image=0)
     arImgOrt[ind] = (arT[0] > arT[1])? 0 : 1;

    // todor debug
    if(DebugMode) {
        //alert("["+obj.width+","+obj.height+"] mode="+((arT[0] > arT[1])? 'verical' : 'hoziontal'))
        writeLog("["+obj.width+","+obj.height+"] mode="+((arT[0] > arT[1])? 'verical' : 'hoziontal')+' src='+obj.src)
    }        
     if (arImgOrt[ind]) {
        GE('mi'+ind).className = 'mImageH';
     }

}
function CompareOrientation(imgOrt){
    var iPhoneOrt = aModeName[isHorizO()];
    GE('omode').innerHTML = iPhoneOrt;
    //alert(imgOrt == isHorizO())
    var sSH = (imgOrt == isHorizO())? 'none' : 'block';
    ShowHideE('vertCover', sSH); 

    var sL = imgOrt? 'H' : 'V';
    if (GE('navig')) GE('navig').className = 'navig'+ sL ;
    if (GE('mainimage')) GE('mainimage').className = 'mainimage'+sL;
    var sPfL = imgOrt? 'Port-<br>folios' : 'Portfolios' ;
    if (GE('PortLnk')) GE('PortLnk').innerHTML = sPfL;

}

function SetGetDim( iMInd){
    var dv = GE('IImg'+iMInd);

    if (dv)   {
        var arI = dv.getElementsByTagName('img');
        if (arI.length>0){
            var oImg =  arI[0];
            oImg.id = 'Img'+iMInd;
            oImg.className = 'imageStyle';
             //YAHOO.util.Event.removeListener('Img'+iMInd,'load');
             YAHOO.util.Event.on('Img'+iMInd, 'load', function(){GetDims(oImg,iMInd);}, true, true);
           //oImg.addEventListener('load',GetDims(oImg,iMInd),true);
        }
    }
}
var occ = new Array();
function PlaceAloneVertImages(){
    var iBLim, iELim;
    iBLim = 0;
    iELim = arImgOrt.length;
    occ[0] = true;
    //occ[iELim]=true;

    for (i=1; i<iELim; i++){
        if ( arImgOrt[i]){//horizontal image
            occ[i]=true;
            continue;
        }else { // current is vertical
            if (!occ[i-1]){//previous is free-alone. this happens only the first time width i=1
                occ[i] = true;
                continue;
            }else {
                if (i+1 == iELim){//this is the last image, it is alone and vertical
                    GE('mi'+i).className = 'mImageV_a'; //***** expand the image container
                }else {
                    if ( arImgOrt[i+1] ){
                        GE('mi'+i).className = 'mImageV_a';//*****expland image container
                        occ[i] = true;
                        occ[i+1] = true;
                        i++;
                        continue;
                    }else { // second vertical image
                        occ[i] = true;
                        occ[i+1] = true;
                        if (arHs[i]>arHs[i+1]) GE('mi'+(i+1)).style.height =  arHs[i]+'px';
                        i++;
                        continue;
                    }
                }
            }

        }


    }
    //arImgOrt

}

function AdjustWebSiteTitle(){

    //if (GE('wstitle')) if (GE('wstitle').offsetWidth > GE('wsholder').offsetWidth) {
    if (GE('wstitle')) if (GE('wstitle').offsetWidth > 325) {
        ShowHideE('dots1','block');
        ShowHideE('dots2','block');
    }
}

function getObjectsByClassName(className, eLTag, parent){
    var oParent;
    var arr = new Array();
    if (parent) oParent = GE(parent); else oParent=document;
    var elems = oParent.getElementsByTagName(eLTag);
    for(var i = 0; i < elems.length; i++)
    {
        var elem = elems[i];
        var cls = elem.className
        if(cls == className){
            arr[arr.length] = elem;
        }
    }
    return arr;
}



////////////////////////////////
///
// todor debug 
var DebugMode = (getQueryVariable("debug")=="1")
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  var sRet = ""
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
        sRet = pair[1];
    }
  }
  return sRet
  //alert('Query Variable ' + variable + ' not found');
} 
var oLogDiv=''
function writeLog(sMes){
    if(!oLogDiv) oLogDiv=document.getElementById('oLogDiv')
    if(!oLogDiv) {
        oLogDiv = document.createElement("div");
        oLogDiv.style.border="1px solid red"
        var o = document.getElementsByTagName("body")
        if(o.length>0) {
            o[0].appendChild(oLogDiv)
        }
    }        
    if(oLogDiv) {
        oLogDiv.innerHTML = sMes+"<br>"+oLogDiv.innerHTML
    }
}

回答by Tracker1

First, Firebug is your friend, get used to it. Second, if you paste each function and some supporting lines, one by one, you will eventually get to the following.

首先,Firebug 是你的朋友,习惯它。其次,如果您将每个功能和一些支持行一一粘贴,您最终将得到以下内容。

var DebugMode = (getQueryVariable("debug")=="1")
function getQueryVariable(variable)

var DebugMode = (getQueryVariable("debug")=="1")
function getQueryVariable(variable)

You can't execute getQueryVariable before it is defined, you can create a handle to a future reference though, there is a difference.

你不能在定义之前执行 getQueryVariable,你可以创建一个未来引用的句柄,但有区别。

There are several other potential issues in your code, but putting the var DebugMode line after the close of the getQueryVariable method should work fine.

您的代码中还有其他几个潜在问题,但在 getQueryVariable 方法关闭之后放置 var DebugMode 行应该可以正常工作。

回答by Dan Breslau

It would help if you gave more context. For example, is

如果您提供更多上下文,将会有所帮助。例如,是

Failed to load source for: http://localhost/js/m.js

无法加载源: http://localhost/js/m.js

the literal text of an error message? Where and when do you see it?

错误消息的文字?您在何时何地看到它?

Also, does that code represent the contents of http://localhost/js/m.js? It seems that way, but it's hard to tell.

此外,该代码是否代表http://localhost/js/m.js? 似乎是这样,但很难说。

In any case, the JavaScript that you've shown has quite a few statements that are missing their semicolons. There may be other syntax errors as well. If you can't find them on your own, you might find tools such as jslintto be helpful.

在任何情况下,您展示的 JavaScript 都有很多缺少分号的语句。也可能存在其他语法错误。如果您自己找不到它们,您可能会发现jslint 之类的工具会有所帮助。

回答by Khyam Shahzad

make sure the type attribute in tag is "text/javascript" not "script/javascript".

确保标签中的类型属性是“text/javascript”而不是“script/javascript”。

回答by Praveen DS

I know it is more than a year since this question was asked, but I faced this today. I had a

我知道问这个问题已经一年多了,但我今天遇到了这个问题。我曾有一个

<script type="text/javascript" src="/test/test-script.js"/>

and I was getting the 'Failed to load source for: http://localhost/test/test-script.js' error in Firebug. Even chrome was no loading this script. Then I modified the above line as

我在 Firebug中收到“无法加载源代码:http://localhost/test/test-script.js”错误。甚至 chrome 也没有加载这个脚本。然后我将上面的行修改为

<script type="text/javascript" src="/test/test-script.js"></script>

and it started working both in Firefox and chrome. Documenting this here hoping that this will help someone. Btw, I dont know why the later works where as the previous one didn't.

它开始在 Firefox 和 chrome 中工作。在这里记录这一点,希望这会对某人有所帮助。顺便说一句,我不知道为什么后来的作品在前一个没有的地方工作。