For my AJAX apps I decided to return a 500 error code if there was some sort of problem on the server side (e.g. user doesn’t have permissions, database error, etc.). That way my onFailure code will be called by prototype and the page will reset itself and let the user know what the problem was. In PHP it just requires a header(’HTTP/1.0 500 We Have a Problem Houston’); Even better is that, because the 500 status code is just a header, I can also pass back XML (i.e. with multiple error messages) if I want.
However, I ran into a problem when debugging this in Safari today. Even though I sent back the 500 status code the onSuccess function was being called in Safari. Alerting the request.status and request.getAllResponseHeaders() gave me “undefined.” After a bit of hunting I figured out that it only happend when my PHP script outputted nothing. The solution? Just have PHP print something (a space suffices) before exiting.
September 10th, 2006 at 9:28 pm
Thanks Jason! I was having this problem today, and your post just saved me endless hours of debugging!
December 4th, 2006 at 2:04 pm
Yep, thank you I was having a problem with Safari as well.
I added echo ” “; //for safari in php script and all work gr8
Happy to have found this quickly! Thanks Google!
January 29th, 2007 at 2:50 pm
Hi
if I want to catch time out status 304?
November 10th, 2007 at 5:40 pm
I’m trying to send an error header like you did, but I also want to send back the error message, how do I do both? The only thing I seem to get back is the error header… Does it stop outputting after the error header is sent?
November 12th, 2007 at 11:05 am
Erik, I know you can send back additional data besides the header so long as you don’t exit after sending the header. Are you echoing XML out in addition to setting the header?