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)'
});
});
Has a
)
the most at the end of.length - 1]);
. Try to remove.– Renato Diniz
Wow, I didn’t even see it, thanks!!!
– Ahri Main