Capture a user action (click a button, for example).
Update the local state, which updates UI.
Send the request.
Get a response.
If negative, rollback update the local state (step 2).
If positive, do nothing or confirm step 2.
Can be simplified if you send ajax request to server first, and then, based on the result, update the local state. Then you dont need to worry about local state rollbacks.
But then if the ajax request fails, you've lost user data.
Rather than rollbacks, I'd use an automatic retry-policy. Then, if that fails notify the user and let him do a manual retry. Should probably have a 'failed operations inbox' for those kinds of notifications.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Can be simplified if you send ajax request to server first, and then, based on the result, update the local state. Then you dont need to worry about local state rollbacks.
But... But...
But then if the ajax request fails, you've lost user data.
Rather than rollbacks, I'd use an automatic retry-policy. Then, if that fails notify the user and let him do a manual retry. Should probably have a 'failed operations inbox' for those kinds of notifications.