May be its a begginer question but i think i forget something which i cant find because i face such error before where ajax returns html page data instead. but this time I am facing one more issue When i click on button it also return login page below of my current page . Instead of redirecting it login page Open the login page below of current page so without further do here is my code
$(document).on("click","#submit_review",function(e){
e.preventDefault();
var review_comment = $("#review_comment").val();
var productid = getUrlParameter('id');
var reviewarray = [review_comment,productid];
var dataArr = JSON.stringify(reviewarray);
$.ajax({
url:"review-ajax.php",
type:"POST",
data:{review:dataArr},
success:function(response){
alert(response);
});
Here is my ajax code
session_start();
if(isset($_POST['review'])){
if(isset($_SESSION['email'])){
$json_data = json_decode($_POST['review']);
$review_comment = htmlspecialchars($json_data[0]);
$product_id = htmlspecialchars($json_data[1]);
$email = $_SESSION['email'];
include "conn.php";
$useridquery = $con->prepare("SELECT * FROM user WHERE email =:email");
$useridquery->bindParam(":email",$email);
$useridquery->execute();
$userresult = $useridquery->fetch();
$userid = $userresult['id'];
$date = date('d-m-Y');
//Insert in the review table
$reviewInsertQuery = $con->prepare("INSERT INTO product_review(product_id, user_id, review_comment,date) VALUES (:product,:user_id,:review,:date)");
$reviewInsertQuery->bindParam(":product",$product_id);
$reviewInsertQuery->bindParam(":user_id",$userid);
$reviewInsertQuery->bindParam(":review",$review_comment);
$reviewInsertQuery->bindParam(":date",$date);
$reviewInsertQuery->execute();
echo 1;
}else{
header('location:loginregister.php');
}
}
?>