I have a strange error within my $.ajax call here:
//CHECK USERNAME
$('#username').focusout(function() {
var id = $(this).attr('id');
var username = ($(this).val());
$(this).removeClass('hint').removeClass('hint_validated');
if (!$(this).val() || !regexUser($(this).val())){
//INVALID
$('#'+id+'_hint').hide().addClass('hint').show().html(usernameInvalid);
}else{
//VALID -> CHECK USERNAME FROM DB IF CONFIG = TRUE
if (checkUsername == true){
//LOADING FROM DB
$('#'+id+'_hint').hide().addClass('hint_check').show().html(usernameCheck);
$.ajax({
cache: false,
type: 'POST',
url: 'classes/ajax_check.php', //all that does currently is echo "USERNAMEVALID"
data: {username: username},
success: function(response){
if (response == "USERNAMEVALID") {
$('#'+id+'_hint').hide().removeClass('hint_check').addClass('hint_validated').show().html(usernameValid);
}else{
alert("ERROR");
};
},
error: function(){
$('#'+id+'_hint').hide().removeClass('hint_check').addClass('hint').show().html(usernameError);
}
});
}else{
$('#'+id+'_hint').hide().addClass('hint_validated').show().html(usernameValid);
}
}
});
The success function is called but the IF clause throws always FALSE. Why?
If the success function is only alert (response); it actually alerts USERNAMEVALID
I’ve worked with these functions before but I can’t find the error here… Thanks for reading, any help is apreciated.
cheer
PrimuS
Check for empty lines. There is a difference between seeing:
You see the same, but it is not. Try this:
Where, it alerts this way:
PS: If you are using a good browser other than IE, please use
console.log()instead ofalert(). So that you can check what is printing and what not!Fiddle: http://jsfiddle.net/XaT6S/