I've got an ajax call and on success, I increment the value of received by 1. getMessage() should only been entered whilst received < 10 is true. However, the return of received outside of the function is always 0, resulting in an infinite while loop.
Anyone have any suggestions so that the updated received value can be seen outside of the function?
var received = 0;
while (received < 10) {
getMessage();
}
function getMessage() {
$.ajax({
url: '/Home/getData/',
type: "GET",
success: function(result) {
received += 1;
}
});
console.log(received);
}
}
});
}