2014-01-05 23 views
-2

我不明白为什么我不能看到我的脚本在成功后的错误(我google这个,它只是提出了大量的答案错误处理jQuery获取脚本的成功/错误事件)。(之后)jquery获得脚本成功我没有看到(故意)错误

如果我这样做与“任意” js脚本对“任意” js脚本

$.getScript('myextrascript.js',function(){console.log('got it!');}); 

重点(我已经尝试了不同的人至少12个不同的脚本),因为经过我的剧本有一个错误刚刚停止脚本(我没有控制台错误)我的第一个想法是这是否发生在我的代码?

说,例如,我的额外脚本有它故意未声明的变量...

myextrascript.js:

console.log('I can see this in the console no problem'); 

var declaired='this variable is ok'; 

undeclaired='this will cause an error'; 

console.log("I now don't see this console log because my code has stopped"); 

我通常会看到错误控制台类似

undeclaired is undefined  myextrascript.js:3 

但我没有看到我的额外脚本里面的错误,即使我把这一行之前我的错误

window.onerror=function(e,script,line){window.console.log("Error: "+e+" ("+script+":"+ line+")");} 

过去不会再有任何想法了,这真是令人费解。

+0

没有,一切都是200 OK(就像我说的这个问题是不是在试图让一个脚本错误)。我强制在该脚本中发生错误,但没有看到向控制台报告的错误。 –

+0

你把它包装在一个* $(function(){}); *?它需要发生DOM准备好后 – yoavmatchulsky

+0

不,我没有包装它(我的代码如上)。我已经尝试设置一个计时器,在dom准备就绪一分钟后运行额外脚本中的代码,但我仍然看不到错误 –

回答

0

解决!

"use strict"; 

window.onerror=function(e,script,line){window.console.log("Error: "+e+" ("+script+":"+ line+")");} 

undeclaired=1; 

console.log('WINNING!'); 

加入 “使用严格的”;现在它的工作/断(碎多么我要!)

Error: Uncaught ReferenceError: undeclaired is not defined (myextrascript.js:12) 
Uncaught ReferenceError: undeclaired is not defined 

enter image description here

相关问题