jQuery/Asp.Net mvc username lookup
- by MD_Oppenheimer
OK, for the life of me I can't uderstand why the follwing code is always returning false?? I have debugged with firefox to see what going on, but the function seems to always return false even when the condition username taken is 0(false), here is the jquery code:
function CheckAvailability() {
showLoader();
$.post("/Account/CheckUsernameAvailability",
{ userName: $(profile_username).val() },
function(data) {
var myObject = eval('(' + data + ')');
var newid = myObject;
if (newid == 0) {
profile_username_error.removeClass("field_not_valid");
profile_username_error.addClass("field_valid");
$("#validUserName_msg").html("<font color='green'>Available</font>")
return true;
}
else {
profile_username_error.addClass("field_not_valid");
profile_username_error.removeClass("field_valid");
$("#validUserName_msg").html("<font color='red'>Taken</font>")
return false;
}
});
}
I'm using the /Account/CheckUsernameAvailability to check if a given name is take or not, it not taken(0) should return true, false otherwise.