我不明白为什么在成功之后我为什么看不到脚本中的错误(我用谷歌搜索,它只是给出了关于jquery get脚本成功/错误时错误处理的很多答案)。
如果我使用“any” js脚本执行此操作$.getScript('myextrascript.js',function(){console.log('got it!');});
强调“任何” js脚本(我已经由不同的人尝试过至少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+")");}
除了这些,别无其他想法了,这真令人困惑。
最佳答案
解决了!
"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
关于javascript - (之后)jQuery获取脚本成功,我看不到(故意)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20933158/