I'm using my first global error handler for ajax calls where I get the error information, send it off to a PHP script and then log the results:
$(document).ajaxError(function(event, request, settings){
//get the error and log the results
var file = window.location.href;
var verbose_error;
verbose_error = 'Ajax error: ' + request.responseText + '\n\n';
verbose_error += 'Status:' + request.status + '\n\n';
verbose_error += 'Status Text:' + request.statusText + '\n\n';
verbose_error += 'Url: ' + settings.url + '\n\n';
verbose_error += 'Data: ' + settings.data + '\n\n';
verbose_error += 'Data Type: ' + settings.dataType + '\n\n';
$.post(getUrl() + 'error/log-ajax-error',{file : file,verbose_error : verbose_error},function(o){
});
});
When I do error handling for my PHP scripts, I can get a stack trace to see which function actually caused the error. Assuming that all of my ajax calls are performed within other functions, can I get the name of the function that caused the problematic ajax call?
For example, in the code below, if the $.post returns an error, I'd like to be able to access the name badAjaxCall, and then put it in my log to help with debugging.
function badAjaxCall() {
$.post(url,data,function(o){
});
}