Question
How can i implement a PHP callback being passed over AJAX with the PHP callback being called by the page requested by AJAX?
The Setup
Comments are posted via AJAX and the paramaters are passed serialized and encrypted (so they can't be changed in transit or carefully crafted AJAX requests to abuse the comments system). The problem is, i need the new total comments amount to update a field in a different mysql table (which will change in every place the comments are used) than what the comments are in themselves.
Example
Someone leaves a comment on a forum topic, that topic needs to know the total comments (without querying the comments table everytime this needs to be known). The problem is, when the comments are posted via AJAX we don't know what the table is to update, what fields, etc as well as having to execute additional code along with it (such as also logging all the members who have left comments on the specific topic).
Solution
I thought about adding two PHP callbacks using closures when declaring the comments widget. These two callbacks (onSuccess() onFailure()) would then be able to do what ever work is needed such as counting the total comments and updating the total comments count for the specific forum topic. Then serialize, encrypt it, pass it as a parameter over ajax, then PHP to decrypt and unserialize the callbacks and execute them.
Why The Solution Breaks
Because closures can't be serialized! Also, i am NOT using eval before anyone suggests it.
The Question Again
How can i implement a PHP callback being passed over AJAX with the PHP callback being called by the page requested by AJAX?
Update
It would appear that some of you are not reading the whole question and understanding that callbacks are to be done in PHP - NOT javascript (using the AJAX callbacks). AJAX is only used to transport the posted comment - not process it (that's what PHP does and that's where the callback comes in which is the problem).