My Scenario:
My Web Page send two AJAX
Calls. Second AJAX
call is sent as a callback for the first AJAX
call in its success
function.
1) In First AJAX
call, I am updating certain contents in a table of a particular user.
2) In Second AJAX
call, I am updating certain contents of some other table of the same user.
My Concern:
Now for some reason if the Second AJAX
call fails (internet issues or something else), I want to make sure that the contents updated during the first AJAX
request is rolled back.
I thought Persistent Mysql Connection may be one solution to this problem, but have few queries:
1) Does this persistent connection belong to that client which initiated or all the requests to Mysql uses the same persistent connection?
2) Is there any better solution for this problem?
UPDATE: I have two AJAX
Calls since I am sending a large base64 encoded image
in one of the AJAX
Calls, and it takes a huge amount of time sending other datas along with the image
The only thing that you can do, is use a cache layer on the server side for the image. Then, after the second step has completed, actually save everything in the database. The cache layer can be something as simple as storing the picture in a temp folder. (Arguably images should be saved on disk instead of in the database anyway.) Once you've uploaded the image all you need to do is to set it's temp path in the session, and use this in the second step.