<script type="text/javascript">
$(document).ready(function(){
$("#submitform").click(function(e){
e.preventDefault();
fname = $(".fname").val();
subject = $(".subject").val();
email = $(".email").val();
phone = $(".phone").val();
comment = $(".comment").val();
$.ajax({
type:"POST",
data:{"fname":fname, "subject":subject, "email":email, "phone":phone,"comment":comment},
url:"http://example/contact/send.php",
contentType: "application/json; charset=utf-8",
success:function(res){
console.log(res);
}
});
});
});
</script>
send.php
<?php
$fname = $_POST['fname'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
echo $fname;
?>
In the above code I am trying to get $fname in my console.log but what happen here when I click on submit button then it show whole PHP code in my console. I don't know why this happening? Please help me.
Thank You