I’m working with Mootools to develop a simple ajax-y page that does some manipulation with db records using PHP as the backend.
I’m submitting the ajax request to a PHP page that calls a function and returns TRUE or FALSE if the record was able to be updated/deleted or not.
However, it seems like the mootools onSuccess event is fired anytime the server returns a 200 status, regardless of the value returned (eg. FALSE is still assumed to be a success).
How do I use onSuccess in a meaningful way, short of returning a 40x error code or something?
Personaly, I feel that using the HTTP status codes to indicate the success/failure of whatever was supposed to happen on the server is incorrect. Everything about the HTTP call itself worked perfectly – the fact that the server was unable to complete the request doesn’t mean the HTTP request failed.
It’s like driving to the store to buy something, only to find it’s out of stock. Returning an HTTP 404, to me, would imply that the store itself was gone. Yet, you’ve successfully driven to the store, walked inside, walked back out, drove home.
So, use a JSON data structure to indicate the results of the requested transaction, which you can check for in your client-side code:
Then in your Moo code:
If the call worked, then you’d have