I'm trying to create a simple JavaScript function which should either return true
or false
.
Instead, it keeps returning undefined
.
My code:
function usernameCheck($username) {
$.ajax({
url: '/cp/login.php',
data: {username: $username},
type: 'post',
success: function(data) {
return data;
// If I console.log() here it shows the correct value (true)
}
});
}
// $u is the value of an input field (e.g. test)
// This console.log() shows undefined.
console.log(usernameCheck($u));