2

I currently have a web-page built in flask where I am selecting data from a mysql database.

I am going to use Javascript (probably inline-edit) to allow the user to edit some text on the web-page.

When the user leaves edit mode, I am going to use ajax to update the table in the database.

However this data will also be within a form, where there will be a submit button and when this is pressed it will run a query that inserts the data into a new table in the database.

My question is;

Will the AJAX inlin-edit function have updated the data (run before the form submit) in the current table before the form submit to the new table as I want the newly edited data in the new table.

I was originally concerned about the asynchronous part but read here that this is not to be worried about.

I am also unsure whether the new data will be available in the new table from the db.

Community
  • 1
  • 1
mp252
  • 453
  • 1
  • 6
  • 18

1 Answers1

0

The fact that the linked question says you functionally don't have to worry about asynchronous, doesn't mean you shouldn't technically worry about it.

If you fire of a normal AJAX request after editing, you send a command to the backend. Normally, in async-mode, you can just press 'submit'. If, for some reaon, the thread handling your first request is slower, you will NOT have your data in your database yet.

So yeah, you should 'worry' (read: take care) of that.

You could do any of the following

  • Call your 'AJAX' synchronously. this is a bit strange, but you could do that
  • Disable your 'submit' button until your ajax has returned

but in the end, you should just look at the flow: you are calling a function and then later another fucntion. If the first should be finished before the second is called, make sure it is. If you just fire off your second (submit), then it's not going to be sure it'll work.

Nanne
  • 64,065
  • 16
  • 119
  • 163