[eluser]craigkoster[/eluser]
My application does quite a bit of AJAX calls to controllers like such:
Code:
$.ajax(
{
type : 'POST',
url : '/ajax/create_account/',
dataType : 'json',
data : $('form').serializeArray(),
success : function (data)
{
//show success message
},
error : function(xhr, ajaxOptions, thrownError)
{
//show error message
}
)
On the controller side, I'd like to be able to do the following:
Code:
function create_account()
{
try
{
if(failure_condition())
{
throw new Exception('There was a problem.');
}
}
catch(Exception $ex)
{
throw $ex;
}
}
When I throw an exception this way jQuery behaves as I would expect and executes the error: handling function but it seems like I can't get a nice clean message from the PHP Exception object. The message is there but it's all formatted with all kinds of other HTML that I have no need for - I just want the message (e.g. 'There was a problem') so I can display it formatted to my liking.
Is there no way to get just the simple message from an Exception object with none of the formatting? This seems pretty odd to me.
Thanks for any insight you can give.
Craig
P.S. - I know someone will ask why I'm using exceptions to send messages - it's because I'd rather not have to have conditional checks in all my jQuery success: handlers to see if the executed AJAX call had any errors in it.