Welcome Guest, Not a member yet? Register   Sign In
Throw Exception From AJAX Call
#3

[eluser]BrianDHall[/eluser]
http://us.php.net/manual/en/language.exceptions.php

According to this getMessage() SHOULD return only the message you have set - but you are getting an uncaught exception error, which is because inside your catch block you are throwing $ex again.

PHP cannot pass the exception as an object to your AJAX browser simply by throwing it. By throwing it you are making PHP ask, "OK, then what do I do with it?" With no catching in PHP it triggers the uncaught exception error.

Instead of throwing the error, you need to return something to your AJAX in string form, such as your getMessage() string, and your AJAX needs to determine if there was an error some other way and then proceed from there. You could for instance check the returned string for "[ERROR]", and in your PHP catch block make the value echo'ed out to return to your AJAX function be "[ERROR]{$ex->getMessage()}".


Messages In This Thread
Throw Exception From AJAX Call - by El Forum - 09-25-2009, 12:21 PM
Throw Exception From AJAX Call - by El Forum - 09-25-2009, 12:38 PM
Throw Exception From AJAX Call - by El Forum - 09-25-2009, 02:55 PM
Throw Exception From AJAX Call - by El Forum - 09-25-2009, 03:17 PM
Throw Exception From AJAX Call - by El Forum - 09-28-2009, 07:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB