jQuery/Asp.Net mvc username lookup

Posted by MD_Oppenheimer on Stack Overflow See other posts from Stack Overflow or by MD_Oppenheimer
Published on 2010-03-25T21:52:59Z Indexed on 2010/03/25 22:23 UTC
Read the original article Hit count: 269

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc