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 (
On your php side, you should echo some json string
, for example I'll do like this on the validateUser.php
:
//Check your database etc.
$user_exists = array('error'=>false,'user'=>true);
echo json_encode($user_exists);
And than with jQuery :
$.ajax({
url: "validateUser.php",
type: "post",
data: "username= " + username,
dataType: "json",
}).done(function(result){
if (result.error == false){
//No errors, check user
if(result.user == true)
alert("Exists"); //now do some stuff
else
alert("User don't exists");
}else{
// There is an error
}
});