I have the following code in a website:
alert('step 1');
// save token if app user:
if (tokenViaApp !== '' ) {
alert('step 2')
$.ajax({
type: "GET",
url: "/includes/notifications/",
data: {
t: tokenViaApp
},
success: function(msg) {
localStorage.token_origin = 'app';
alert('step 3')
}
});
}
alert('step 4')
If the if()
passes, then i would think the alert should be in this order:
step 1
step 2
step 3
step 4
but instead I get:
step 1
step 2
step 4
step 3
Why is this the case? and how can this be changed to process correctly?