What is wrong with my script? It has a global variable which is later set with a function, but it comes back as undefined. Why is that?
<script>
var userName
function getAnonUserName() {
$.ajax({
url: "https://ck:8081/get-username",
type: "get",
success: function(response) {
userName = response
}
})
}
window.onload = function() {
getAnonUserName()
console.log(userName)