0

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));
user3378165
  • 6,546
  • 17
  • 62
  • 101
Chris
  • 1,574
  • 4
  • 16
  • 49

0 Answers0