I write a simple script with php and mysql for rating of products on my website when I click on Like link it send product id through ajax and get total number of likes of products. But when I click on Like link page redirect to page.php but I want that my index page not redirect to page.php but product id send to page.php. I use this simple html tag. Please help to resolving this issue.
<a href="page.php?id=ABC">Like</a>
<div class="likediv"></div>
AJAX/JQUERY
$(document).ready(function(){
var catValue = "ABC";
$.ajax({
type:"post",
url:"ajax_likedproduct.php",
data:"catValue="+catValue,
success: function(data){
$('.likediv').text(data);
}
});
});
PHP
if(isset($_POST['catValue'])) {
$data = $_POST['catValue'];
$sql = mysql_query("SELECT SUM(likes) AS TotalLike FROM likes WHERE product_id='".$data."';");
while($likes = mysql_fetch_assoc($sql)){
if($likes['TotalLike'] == 0 || $likes['TotalLike'] == ""){
echo'0';
}else{
echo $likes['TotalLike'];
}
}
}