我試圖用錯誤處理try/catch來捕捉Ajax錯誤,但它不工作。這裏是我的代碼:Javascript錯誤處理不起作用
var ajaxrequest=null
if (window.ActiveXObject){
try {
ajaxrequest=new ActiveXObject("Msxml2.XMLHTTP")
}
catch {
try{
ajaxrequest=new ActiveXObject("Microsoft.XMLHTTP")
} //end inner try
catch {
alert("NOT WORKING!!")
} //end inner catch
} //end outer catch
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
ajaxrequest=new XMLHttpRequest()
ajaxrequest.open('GET', 'inventory.php', true) //do something with request
我做錯了什麼?
也許它只是不會拋出一個例外...... – 2013-10-31 19:50:38