Proper mechanism for sending PHP errors to the client

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-07T14:09:02Z Indexed on 2010/04/07 14:13 UTC
Read the original article Hit count: 156

Filed under:
|
|

Greetings,
I was trying to discover a proper way to send captured errors or business logic exceptions to the client in an Ajax-PHP system. In my case, the browser needs to react differently depending on whether a request was successful or not. However in all the examples I've found, only a simple string is reported back to the browser in both cases. Eg:

if (something worked)
    echo "Success!";
else
    echo "ERROR: that failed";

So when the browser gets back the Ajax response, the only way to know if an error occurred would be to parse the string (looking for 'error' perhaps). This seems clunky.

Is there a better/proper way to send back the Ajax response & notify the browser of an error?
Thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about AJAX