getUsers();
function getUsers(){
console.log('Start');
$.ajax({
url: 'https://jsonplaceholder.typicode.com/users',
method: 'GET',
dataType: 'json',
success: function (data) {
data.forEach(user => {
console.log(user.id);
});
},
error: function () {
console.log(data.status);
}
})
console.log('End');
}
The above code-example should print the following: Start ids ... End
However it has the following problem: The order of printing of the data is wrong. It prints Start End data-object
I know it has to do with async, however I can't fix the problem. I tryed alot of things like $.When() Promise async/await But none of them helped.
So could you please show how to fix this problem?
Thank you in advance