The essence of the problem: Function (x) sends a request to the php file, there it is processed and UPDATE happens in sql. After sending the request, the function (y) is called which updates the state directly in html, it makes a request to the database and sees what is there. So, when calling (x), the data on the page remains previous, that is, if we ..
write to database: 1 is displayed 0
write to database: 2 is displayed 1
and so on, I think the essence is clear. I thrust the function (y) in timeOut, but it does not save that what can be done in this situation?
function dbWrite(id, name) { var que = 'UPDATE test SET name = ' + name + ' WHERE id = ' + id; $.post( 'connect.php', {query: que}, function(answer) { }); setTimeout(test1(id), 1000); } function test1 (id) { $.post( 'connect.php', {id: id,}, function(workJson) { alert(workJson); }); }