JavaScript函数导致未定义

时间:2016-07-17 07:25:10

标签: javascript php

我正在尝试创建一个简单的JavaScript函数,该函数应返回truefalse

相反,它会不断返回undefined

我的代码:

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));

0 个答案:

没有答案
相关问题