I have a PHP script that logs informational and error messages to a database table. I want to build a javscript singleton to use to call this script with parameters based on the info or error that I need to log. The PHP script checks to see if the logonly parameter is set, and if so, only logs the values, if it is not set, it logs the error and also emails me that it wrote to the log so I can check it immediately when I get the email.
Here is the javascript singleton:
[BrowserDetect is a class for browser detection: http://www.quirksmode.org/js/detect.html]
var NATools = {
var browser = BrowserDetect.browser;
var browserVer = BrowserDetect.version;
var browserOS = BrowserDetect.OS;
var AJAX_ERROR_LOG_URL = '/ajax/log_ajax_error.php';
DebugLog: function(log_only, url, msg, browser, browserVer, browserOS, jqXHR, exception) {
var logurl = AJAX_ERROR_LOG_URL;
if(log_only) {
var logurl += '?logonly=yes&url='+url+'&browser='+browser+'&browserVer='+browserVer+'&browserOS='+browserOS;
} else {
var logurl += '?status='+jqXHR.status+'&object='+jqXHR+'&error='+jqXHR.responseText+'&expmessage='+exception.message+'&url='+url+'&browser='+browser+'&browserVer='+browserVer+'&browserOS='+browserOS;
}
$.ajax({
async: true,
type:'POST',
url: logurl,
dataType: 'json'
}); // $.ajax
}; // DebugLog
}; // NATools
Here is how it would be called in an informational situation:
// url is preformed in this situation
NATools.DebugLog(true, url, "Good Entry", browser, browserVer, browserOS);
Here's how it would be called in an ajaxError situation:
$(document).ajaxError(function(e, jqxhr, settings, exception) {
var ajax_url = settings.url;
NATools.DebugLog(false, ajax_url, "Error Entry", browser, browserVer, browserOS, jqxhr, exception);
}); // ajaxError
My question is, do I need to pass NULLS for the jqXHR and exception parameters in the informational situation? Or is it possible to set default optional parameters here?