franko75 Posted February 29, 2012 Share Posted February 29, 2012 I'm trying to debug a sporadic 500 error which users occasionally get when filling out form sections on my site. Whenever it happens, I try to recreate their environment and fill out the form exactly as they have done, but can never recreate the issue. I have checked my application logs for the framework I am using, but they report nothing related to the error. I'm hoping someone here might be able to help me catch this. This is where the 500 error is sometimes happening and this triggers the error which users report: //In jquery AJAX function, which submits data to PHP form for processing error: function(data,transport){ $.validationEngine.debug("error in ajax response: "+data.status+" "+transport) } Is there a way for me to try and catch what the exact error is here? The problem is I can't recreate the error, either using an AJAX call or not to call the PHP script. I need to catch the error response from the PHP script being called, but I never get an error when trying to recreate the user issue, i.e same OS/browser/form answers. The Apache error logs for the site have very little - unless I'm looking in the wrong place. I'm on CentOS, ran locate error_log and got an error_log.txt file in my vhosts directory for my site, but this just contained a 302 message log, nothing else. I also tried locate error | grep mysite. Quote Link to comment https://forums.phpfreaks.com/topic/257970-how-to-debuglog-500-error-in-ajax-response/ Share on other sites More sharing options...
codebyren Posted February 29, 2012 Share Posted February 29, 2012 I'm not sure this will help since I'd also expect the error to be logged in the framework or server logs as you mentioned, but... The error handler for ajax calls made via jQuery should have access to many details about the error on the client side. You could gather whatever you want from this and then post it to a custom URL (again via AJAX) that will log the data for your review at a later stage. I don't know all that much about the properties of the jqXHR object (assuming jquery version 1.5+) but something like this might work: $.ajax({ // Set usual parameters here // ... // Handle any errors error: function(jqXHR, textStatus, errorThrown) { var my_error = 'Error: ' + textStatus + ', HTTP code:' + jqXHR.status + ', Response text: ' + jqXHR.responseText; // Maybe add some other interesting info like jqXHR.getResponseHeader('content-type') // Do a follow-up ajax post to log these details server-side and hope it works. } }); There's more info about the jqXHR object . It's a bit of a round-about way of getting the error but it will hopefully provide you with more info than you have now... Quote Link to comment https://forums.phpfreaks.com/topic/257970-how-to-debuglog-500-error-in-ajax-response/#findComment-1322410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.