Jump to content

How to debug/log 500 error in Ajax response


franko75

Recommended Posts

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.