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

233
Visualizações
Unable to get button value/attribute in jquery using php loop

I'm working on "like" and "dislike" module in jQuery with PHP,And I'm facing these two problems:

  1. Right now unable to get id of button (like=1, dislike=0)
  2. Query showing correct result but how to display ajax response under "like dislike" section ?

Here is my code, following code inside foreach loop:

<?php foreach // ?>
 <form class="form-horizontals1" method="post" >
                <input type="hidden"  id="ReviewId" name="ReviewId" value="<?php echo $rev->id;?>">
                
             <button class="likebutn_r" id="show<?php echo "1";?>"  type="submit"><img src="<?php echo base_url(); ?>/assets/img/thumb.png" height="24" width="24"></button>
             <label class="lilkcount">10(dynamic) </label>
            
            <button class="likebutn_r" id="shows<?php echo "0";?>"  type="submit"><img src="<?php echo base_url(); ?>/assets/img/thumbdown.png" height="24" width="24"></button>
             <label class="lilkcount">5(dynamic)</label>
        <div id="counter"></div>
        </form>
    <?php end foreach // ?> 
<script type="text/javascript">
    $(document).ready(function(){
        //likebutn_r
        $('.form-horizontals1').submit(function(e){
            
var ids = $(this).attr('ids');
 console.log(ids);          
        alert($(this).attr("id"));  
                e.preventDefault(); 
 $.ajax({
 url:'<?php echo base_url();?>main/AddVote',
 type:"post",
 data:new FormData(this),
 //dataType: 'json',
 processData:false,
 contentType:false,
 cache:false,
 async:false,
 success: function(data){
     console.log(data);
     alert(data);
    $('#counter').html(data); 
 }
 
 });
        });
    });
</script>
    

Here is my controller code, please tell me how I can get "like dislike" value in script and how I can show result in views ?

function AddVote()
    {
        $ReviewId=$_POST['ReviewId'];
        $vote=$_POST['vote'];
        echo $result['TotalUpVotes'] = $this->M_main->CountSubmittedCoinVote($ReviewId,$vote);
        echo $result['TotalDownVotes'] = $this->M_main->CountSubmittedDownVotes($ReviewId,$vote);
    } 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. First, move the form ouside the loop.

     <form class="form-horizontals1" method="post" >
     <?php foreach // ?>
     <div class="my-rev-container js-rev-container">
     ...
     </div>
     <?php end foreach // ?>
     </form>
    
  2. Add a class to the inputs, you whould access with

     <input type="hidden" class="js-form__rev" id="ReviewId" name="ReviewId" value="<?php echo $rev->id;?>">
    
  3. Finaly access them

     $('.form-horizontals1').submit(function(e){
     var ids = $(this).find(".js-form__rev");
     console.log(ids);
    
about 4 years ago · Juan Pablo Isaza Relatório
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