Ahh... well have you thought about using a Javascript framework?
I use prototype to manage my AJAX calls on the javascript side.
In prototype.... when you make an AJAX call you can set two different functions to process the response: one for when the 200 SUCCESS code is returned and one for when 500 Internal Server error is returned.
Then server side, when I see an error I set the HTTP return code to 500 before I quit the script.
header("HTTP/1.1 500 Internal Server Error");
If you don't use a frame work.. you can still query for the HTTP status with something like this.
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200)
successHandler(xmlhttp.responseText);
else if (xmlhttp.status==500)
errorHandler(xmlhttp.responseText);
}