AJAX with CHTML Image YII Framework

0

Hello, I'm trying to make an AJAX request with a Chtml Image. When a user clicks on this image the request is made through a jQuery function, however I'm having trouble getting the image path, my variable named path in the function does not return the path, what's wrong with it? Here is the code below:

Image:

 echo CHtml::Image($string, '', array(
 'id' => 'cimagem', 
 'style' => 'width: 50%;',
 'class' => 'bimagem',
)); 

jQuery:

  $('.bimagem').on('click', function(){
     alert('asd');
     var path = $('#cimagem').attr('src').split('\/')[($('#cimagem').attr('src').split('\/')).length - 1]);
     $.ajax({    
                url: '<?php echo $this->createUrl('Produtos/SendImage'); ?>',
                data: {caminho: path}
                type: 'POST',
                dataType: 'json',
                cache: false,
                success: 'alert(this)'
            });
    });
    
asked by anonymous 21.05.2018 / 15:07

0 answers