my issue is as following,i have to display an error msg in 3 cases 1- some text is missing 2- telephone number should be all digits 3- email format is invalid the $errmsg is a JSON object that should display that message after being parsed in the ajax.but i don't know how to parse it in the ajax and return the value. here is my code:
$errmsg='{"invalid":"some text missing",
"mailerr":"email format is incorrect",
"telephoneerr":"telephone should be all digits"}';
if(($name=="")||($email=="")||($telephone=="")||($username=="")||($password==""))
{
echo $errmsg;
}elseif(!preg_match($pattern_email,$email)){
echo $errmsg;
}
elseif (!preg_match($pattern_phone,$telephone)){
echo $errmsg;
}
and the ajax code is as follows:
$.ajax({
type:'POST',
url: 'contactData.php',
//dataType: "JSON",
data{"name":name,"telephone":telephone,"email":email,"username":username,"password":password},
success: function(data) {
$("#validate").html(data);
}
});