I am learning how to use ajax to check if registered email data already exists in the system. But when used, the result returned from success:function(data) is always the source code of the original php page (as shown in the image below). Here is my javascript code
$(document).ready(function(){
$("#email").change(function(){
$.ajax({
URL: "process-email.php",
type: "post",
data: {email:$(this).val()},
success:function(res) {
console.log(res);
}
})
})
})
This is the destination for data processing
<?php
include "config/config.php";
$result = mysqli_query($conn,"SELECT * FROM tb_user WHERE email='" . $_POST['email'] . "'");
if(mysqli_num_rows($result) <= 0)
{
echo "OK.";
}else{
echo "Already exist.";
}
?>
And here is the data sent to my main site
Is there any way to fix it? Thanks everyone!