我写了一个函数,它必须检查是否已经使用了用户名.现在当我从另一个函数调用该函数时,并提示它的返回值:
alert(checkusernameavailable('justausername'));
它说"未定义".我搜索过高低,但找不到我做错了什么.我想它应该只返回check.php中的php-echo,但事实并非如此.这是我写的函数:
var checkusernameavailable = function(value) {
$.ajax({
url: "check.php",
type: "POST",
async: false,
cache: false,
data: "username=" + value + "",
success: function(response) {
alert(response);
return response;
},
error: function() {
alert('ajax error');
}
});
}
我究竟做错了什么?