Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
How topass AJAX variables to another JS function

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>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!