How to use dataType in ajax when you sending data to server and returning value is echo json_encode("1")
which is text not json, please check the below code for ajax:
$.ajax({
type: "GET",
url: "http://www.pzishkstan.com/MobileApps/controller.php?city="+$city+"&disease="+$disease+"&name="+$name
crossDomain: true,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
dataType: "json",
data:'type=register',
success: function(data) {
if(data=="1"){
alert("yes");
}else{
alert("no");
}
},
error: function(e) {
alert('Error: ' + e.message);
}
});
and my php code:
$name=$_GET["name"];
$city=$_GET["city"];
$disease=$_GET["disease"];
$birth=$_GET["birth"];
$start=$_GET["start"];
$graduate=$_GET["graduate"];
$email=$_GET["email"];
$mobile=$_GET["mobile"];
$pass=$_GET["pass"];
$web=$_GET["web"];
$certi=$_GET["certificate"];
$social=$_GET["social"];
$uni=$_GET["uni"];
$note=$_GET["note"];
$gender=$_GET["gender"];
$explode = explode('/', $_GET["image"]);
$image="upload/".array_pop($explode).".png";
$queryNumber="INSERT INTO doctors (Name,Birthdate,StartDate,GraduateDate,Mobile,Email,password,proPic,Website,Gender,Certifications,Socials,City,
GraduationUniversityName,Notes,regDate) values('$name','$birth','$start','$graduate','$mobile','$email','$pass','$image','$web','$gender','$certi','$social','$city','$uni','$note',
CURRENT_TIMESTAMP)";
$numberOfRows = mysqli_query($link,$queryNumber) or die(mysql_error());
if($numberOfRows>0){
$query=mysqli_query($link,"select * from doctors where Mobile='$mobile'");
while($row=mysqli_fetch_array($query)){
$id=$row["DoctorsId"];
mysqli_query($link,"INSERT INTO specializationdoctor (doctorId,specializationId) values($id,$disease)");
}
echo json_encode(array("response" => "1"));
}
else{
echo json_encode(array("response" => "0"));
}
My error is :
I have been searched in google I couldn't find any perfect answer.