Ajax call is not responding give me a empty result (PHP) code is properly working only issue i have is with ajax. I'll already check all the CDN is working fine
My html code :
<form method="post">
<input type="hidden" name="product_id" id="product_id" value="<?= $id ?>" >
<input type="hidden" name="user_id" id="user_id" value="<?= $_SESSION['id'] ?>">
<textarea name="comment" id="comment" cols="30" rows="10"></textarea>
<input type="hidden" name="rating" id="rating">
<input type="submit" name="c_submit" id="c_submit">
</form>
<ol id="comment"> </ol>
My php code :
<?php
include "../../functions/dbs.php";
if (isset($_POST["c_submit"])){
$product_id = $_POST['product_id']; $user_id = $_POST['user_id'];
$comment = $_POST['comment']; $rating = $_POST['rating'];
$query = "INSERT INTO user_profile (product_id,user_id,comment,ratting) values ('$product_id','$user_id','$comment','$rating')";
print_r($query);exit();
$sql=mysqli_query($con->connect(),$query);
?>
<li class="box">
<?= '<span class="email">' . $product_id. '</span>' ?>
<?= '<span class="comment">' . $comment . '</span>' ?>
</li>
<?php } ?>
My ajax code : If user can click on submit all the result that we have in input field will be shone in ol#comment.
$(function () {
$("#c_submit").click(function() {
var product_id = $("#product_id").val();
var user_id = $("#user_id").val();
var comment = $("#comment").val();
var rating = $("#rating").val();
var dataString = 'product_id =' + product_id + '&user_id=' + user_id + '&comment=' + comment + '&rating=' + rating;
if (product_id == '' || user_id == '' || comment == '' || rating ==''){
alert('Please Give Valid Details');
}else {
$.ajax({
type: "POST",
url : "include/comm.php",
data : dataString,
cache: false,
success : function(html){
console.log(html);
$("ol#comment").append(html);
$("ol#comment li:last").fadeIn("slow");
}
});
}
});
});
Ignore :
"The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz. Brick quiz "