I have this function to unlock the list that the user is currently editing:
function unsetLock(id) { $.ajax({ type: "POST", url: "/ajax.php?action=unsetLock", dataType: 'json', data: "id="+ id }); return true; }
When the user goes from the list, I have to cancel the lock:
unsetLock(lockID); document.location.href='/page/to/navigate/back/to.php';
However, this unlocking sometimes works, and sometimes not. I think this is because document.location.href is executed before the ajax call was actually sent to the server.
How can I force unlock to go to the next page?
Actually, I do not need to wait for Ajax-Reply, since I want to redirect the user whether he is successful or not. I just want to make sure that it is being transmitted to the server.
If I put document.location.href inside the Ajax function, it will wait for a response.
javascript jquery ajax
Jochenjung
source share