Arrghh, I know there is ways to do this but it just won't work for me.
I have a page, that on load light up icons if they exist in my database.
Icons that are still are disabled have a onclick-function connected to them. This onclick-function then calls another function that adds the icon to my database (which is a asynchronous function). When this asynchronous function is done I want to reload the page so that my icons light up again, this time with the new icon that were added to my database.
It does reload, but to fast. It doesnt seem to wait for the asynchronous function to be done. In other words my icon wont light up on click, but when I refreshes my page manually after I have clicked it, the icon lights up.
Here is my function that I think should work.
$.when(addUserToNetwork(response.email, 2, response.id)).done(function(){location.reload();});
This:
addUserToNetwork()
is my asynchronous function. When this is .done I want to reload the page.
What am I doing wrong?
Here's my code for addUserToNetwork function():
function addUserToNetwork(_email, _networkID, _idAtNetwork){
return $.ajax({
url: '/fb/updateUserNetwork',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({email:_email, networkID:_networkID, idAtNetwork:_idAtNetwork}),
dataType: 'xml/html/script/json'
});
}