【发布时间】:2012-12-09 23:33:56
【问题描述】:
我正在使用 Chrome 来调试我的网站。但是,有时我会遇到这样的错误:
错误
Uncaught TypeError: Cannot set property 'display' of undefined
堆栈跟踪
f.extend.ajax
ClassLoader.performLoadWave
所以,我知道它在我的 Ajax 调用中,可能在我的成功函数中。但是,我的成功函数调用了很多东西。
我并不是真的在找人来帮助我调试我的代码,而只是问我如何调试它。我使用了很多 console.log();但它们并没有真正的帮助,我怎样才能正确地找到像这样的错误?
编辑
补充一下我的问题,在这个例子中,错误出现在一个由我的 AJAX 调用加载的文件中,因为 dataType 设置为“脚本”,但我怎么能知道这一点而无需挖掘几个小时?
代码
对于任何关心我的代码的人,这里是:
$.ajax({
url: filePath,
async: false,
cache: !Settings.debugging,
dataType: 'script',
error: function(httpRequest, message, errorThrown){
if(errorThrown == 'Not Found')
{
throw 'Include cannot be found.';
}
else
{
throw errorThrown + ': ' + (message == 'parsererror' ? 'This doesn\'t look like JavaScript!' : message);
}
},
success: function(){
$.each(newNeedsLoading, function(index, element){
if(element !== undefined)
{
var className = element.className;
if(window[className] && window[className]['included'])
{
window[className]['included']();
}
className = 'Plugin_' + element.className;
if(window[className] && window[className]['included'])
{
window[className]['included']();
}
className = 'Plugin_Administration_' + element.className;
if(window[className] && window[className]['included'])
{
window[className]['included']();
}
if(element.completed)
{
element.completed();
}
}
});
ClassLoader.isLoading = false;
}
});
【问题讨论】:
-
查看副本,我刚刚在 $.ajax 调用中添加了 crossDomain: true,现在可以正常调试了。