AJAX with CHTML Image YII Framework

Asked

Viewed 26 times

0

Hi, I’m trying to file an AJAX request with a Chtml Image. When a user clicks on this image the request is made through a jQuery function, but I’m having trouble picking up the image path, my variable named path in the function does not return the path, what’s wrong with it? Follow 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)'
            });
    });
  • 1

    Has a ) the most at the end of .length - 1]);. Try to remove.

  • Wow, I didn’t even see it, thanks!!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.