myscript.js -


$(document).ready(function(){



 $("#submit-btn").attr("disabled",true);


$("#email").on("blur",function(){

var email = $(this).val();

console.clear();

console.log("Email ="+email);


//Now fire ajax request

$.ajax({

url:BASE_URl+"check-email.php",

data:{

user_email:email,

},

type:"POST",

dataType:"json",

success:function(response){

// console.clear();

// console.log(response);


if(response.response_code==200){

var data = response.response_data; //Json_helper Keys

if(response.status==false){


                          $("#email").css("border","2px solid red");

                          $("#spn-email").html(response.comments);

                           $("#spn-email").css("color","red");

                         

}else{


  $("#email").css("border","2px solid green");

                          $("#spn-email").html(response.comments);

                          $("#spn-email").css("color","green"); //Json_helper Keys

                             


}

}


}


});


});

});



---------------------------------



 <?php


header("Content-Type:application/json");

if($_SERVER['REQUEST_METHOD']=='POST'){

 

  $email = isset($_POST['user_email'])?$_POST['user_email']:NULL;

if(is_null($email) or empty($email)):

  json_bind([], 200, "Email cannot be Empty", false);


  else:

  $email = sanitise($email);


  if(@doexist('tbl_student',['email'=>['=',$email],])):

        json_bind([], 200, ' Email Already Exist', false);

  else:

  json_bind(['email'=>$email], 200, '* Unique Email', true);


  endif;

  endif;


json_bind([], 201, '* Invalid Request', false);

}

?>