0

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

Abhinav
  • 8,028
  • 12
  • 48
  • 89
  • 1
    yes you have a problem 2 ajax calls,why 2 and not just one? – madalinivascu Sep 22 '16 at 06:11
  • having transaction security with ajax wont work ( cant store the transaction information anywhere ). So, you are down to updating your schema, so you can write all the information in one call, or do some nasty database thingies ( e.g. a trigger -> http://stackoverflow.com/questions/16892070/mysql-after-insert-trigger-which-updates-another-tables-column ) – Najzero Sep 22 '16 at 06:14
  • @madalinivascu: pls see my update in the question, thats why I am using two AJAX callas – Abhinav Sep 22 '16 at 06:28

1 Answers1

0

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.

ChristianF
  • 2,068
  • 9
  • 14