我使用Chrome來調試我的網站。不過,有時我想出了這樣一個錯誤:如何調試jQuery AJAX
錯誤
Uncaught TypeError: Cannot set property 'display' of undefined
堆棧跟蹤
f.extend.ajax
ClassLoader.performLoadWave
所以,我知道這是什麼東西在我的Ajax調用,可能在我的成功功能。但是,我的成功功能要求很多東西。
我真的沒有找人幫我調試我的代碼,只是問我該如何調試。我使用了很多console.log();但他們不是很有用,我怎麼才能找到像這樣的錯誤?
編輯
要添加到我的問題,在這個例子中,錯誤的是在得到我的AJAX調用加載的文件,因爲該數據類型設置爲「腳本」,但我怎麼能知道這無需挖掘幾個小時?
代碼
對於任何人,關心我的代碼,這就是:
$.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;
}
});
可能重複/stackoverflow.com/questions/690781/debugging-scripts-added-via-jquery-getscript-function) – jValdron 2012-02-07 18:46:59
查看重複內容,我剛剛在我的$ .ajax調用中添加了crossDomain:true,現在可以正確調試。 – jValdron 2012-02-07 18:48:04