Which is best: updating database then the page with data or update page with data then the database (quicker)?

Which is best: updating database then the page with data or update page with data then the database (quicker)?

Hi

I am new to JQuery, but am quickly picking it up.

I have a table of data with a form to add more data using JQuery without page refresh. So the JQuery adds the data to the database then adds the new data to the table. At the moment it adds it to the database, then using JSON sends it back which I use to add to the table. So this method guarantees the data has been added before updating the page.

BUT there is a delay of course for the user. What would be better for the user is update the table first (so it looks instant to the user) THEN update the database. The problem is if the data was not added to the database for whatever reason. The user thinks it would have.

So wondered what is best? Ideally I want the user to see an instant update, then add the data to the DB afterwards in the background. But not have any issues with adding data to the DB.

Thanks