0
這可能嗎?我有一個處理程序,不斷追加字符串信息到一個字符串每次錯誤命中,然後在窗口卸載我想通過AJAX發送這個信息到服務器,window.onerror&捕捉多個錯誤
但一旦錯誤已被處理,似乎無法處理另一個,這是因爲他們是致命的錯誤?或者我錯過了什麼?
ErrorManager: (function() {
function Init(message) {
InitErrorHandler();
InitAjaxHandler();
}
function InitErrorHandler() {
Data.ErrorHandlerText = "";
Data.ErrorHandlerCount = 0;
window.onerror = function(errorMessage, url, line) {
Data.ErrorHandlerText += ("Error: "+(Data.ErrorHandlerCount+1)+" \n\n");
//Get error specific info
Data.ErrorHandlerText += escape(errorMessage) + "\n";
Data.ErrorHandlerText += escape(url) + "\n";
Data.ErrorHandlerText += escape(line) + "\n";
Data.ErrorHandlerCount++;
return true;
}
}
function InitAjaxHandler() {
window.onbeforeunload = function() { //when browser closed
Data.ErrorHandlerCount > 0 && SendErrorsToAjax();
}
}
function SendErrorsToAjax() {
PrepareErrorsForAjax();
//$.getJSON(Interface.Utility.PrefixURL('/emailjserrors/'+Data.ErrorHandlerText), AjaxCallback);
}
function AjaxCallback(response) {
}
function PrepareErrorsForAjax() {
var preText = "A user has encountered a few errors: \n\n";
//Get session info
var userAgent, activePageID, accountNO, consumerNO;
userAgent = escape(navigator.userAgent);
preText += "User agent: "+userAgent+" \n";
if($.mobile.activePage != null) {
activePageID = $.mobile.activePage.attr('id');
preText += "Page ID: "+activePageID+" \n";
}
//Get info that may or may not be set
if(Data.authJSON != null && Data.authJSON.consumer != null) {
preText += "Account Number: " +Data.authJSON.consumer.accountNo+" \n";
preText += "Consumer Number: "+ Data.authJSON.consumer.consumerNO+" \n";
}
preText += "\n The following errors were encountered:\n\n";
Data.ErrorHandlerText = preText + Data.ErrorHandlerText;
}
return {
Init: Init,
SendErrorsToAjax: SendErrorsToAjax
}
})(),