I am trying to populate the error to the user using ajax, values are saving in a database properly in every query but when trying to show the same in the front end it is not reflecting the same to the end-user.I wanted to populate the status to the end-user using ajax.
Here is my AJAX code
$.ajax({
url:"controller/client-registration-Controller.php",
type:'POST',
contentType:false,
data:data,
dataType : 'json',
cache: false,
processData:false,
beforeSend: function(){
$('#insert').attr("disabled","disabled");
$('#fupForm').css("opacity",".5");
},
success: function(strMessage) {
$responseText=JSON.parse(strMessage);
if($responseText.status=='OK')
{
toastr.success(' Registered Successfully.', 'Success Alert', {timeOut: 5000});
//clear all fields
$('#fupForm').trigger("reset");
}
else if($responseText.status=='ERR'){
toastr.error('You Got Error', 'Something Went Wrong!', {timeOut: 5000});
}
}
});
}
});
});
</script>
Here is my PHP Code
if (mysqli_num_rows($query) > 0) {
header('Content-Type: application/json; charset=UTF-8');
$response['status'] = 'ERR';
$response['message'] = "Mobile is already exist";
return json_encode($response);
$res = " Mobile is already exist";
echo json_encode($res);
} elseif (mysqli_num_rows($query1) > 0) {
header('Content-Type: application/json; charset=UTF-8');
$response['status'] = 'ERR';
$response['message'] = "Email is already exist";
return json_encode($response);
$res = "Email is already exist";
echo json_encode($res);
} elseif (!mysqli_query($con, $sql)) {
$response['status'] = 'ERR';
$response['message'] = "Something Went Wrong";
return json_encode($response);
$res = "Something went wrong";
echo json_encode($res);
} else {
header('Content-Type: application/json; charset=UTF-8');
$response['status'] = 'OK';
$response['message'] = 'Inserted successfully';
echo json_encode($response);
return;
// $error="Registered Successfully";
// echo json_encode($error);
}
}
}}
I want to populate the status in the front end