I\'m a bit confused on how to use the ajax .done() function. I\'m working on validating a form to check if a user exists in database and though ajax would be the best approach (
I think it should be result == 'true' as the result is a data string
I just checked, I am correct, the quotes make it work
PHP:
Javascript
username='sambob';
$(".check").blur(function(){
$.post("validateUser.php", { username: username })
.done(function(data) {
if (data == 'true'){
alert("User exists");
}else{
alert("User doesn't exist");
}
});
});
json PHP
json Javascript
$(".check").blur(function(){
$.post("validateUser.php", { username : username },
function(user){
if (user.exists == true){
alert("User exists");
}else{
alert("User doesn't exist");
}
}, "json");
});