Hi everyone I am currently developing a catalog and I manage user comments on products which works well, but I have now decided to use AJAX to do it but unfortunately I am new to AJAX and it creates a bit of trouble for me for the moment. I would like to pass the 'id' and 'pageNumber' variables to the getReviews () function so that it can use them in the url
HTML
<body>
<ul>
<li><a class='page-link is-active' data-id=".$prodId." data-link=".$counter.">$counter</a></li>";
<li><a class='page-link' href='$ver=$counter' data-id=".$prodId." data-link=".$counter.">$counter</a></li>";
</ul>
<div id='display_reviews' class="col-md-7"></div>
</body>
AJAX
<script>
$(document).ready(function(){
getReviews();
$(document).on('click', '.paging li a', function(e){
e.preventDefault();
var id = $(this).data('id');
var pageNumber = $(this).data('link');
$.ajax({
type: 'GET',
url: '/mysite/product/?action=getProductReviews&id='+id+'&page='+pageNumber,
dataType: 'json',
success: function(response){
getReviews();
}
});
});
function getReviews(){
$.ajax({
type: 'GET',
url: '/mysite/product/?action=getProductReviews&id='+id+'&page='+pageNumber,
dataType: 'json',
success: function(response){
$('#display_reviews').html(response);
}
});
};
});
</script>