Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda