0
I got this foreach()
<?php foreach($fotos_ingresso as $valor){ ?>
<div id="fotos-listagem-imagem">
<a href="javascript:;" data-toggle="modal" data-target="#confirma-deletar-imagem" data-href="#" data-id="<?php echo $valor->inf_id; ?>" id="deletar-imagem"><img src="<?php echo base_url('assets/uploads/interno_fotos/'.$valor->inf_tipo.'/'.$valor->inf_imagem); ?>" class="img-responsive corte-imagem"></a>
</div>
<?php } ?>
Inside it, I am passing id="delete-image" and also the data-id.
How do I get the data-id back? I did it this way:
$('#confirma-deletar-imagem').on('show.bs.modal', function(e) {
var inf_id = $(this).attr('data-id');
});
In this case it is returning null. When you click on the image, I open a confirmation via modal... And when you click, you must call Ajax to remove. However, I don’t even know how to call ajax to remove, after clicking on the button called delete-image-modal.
How can I do that?
The attribute
id
defines a unique element on the page, so it makes no sense to have inside aforeach
. See if you can use classes.– Woss
Foreach() is for me to display the images from the database, so I’m using foreach()...
– Sr. André Baill
Yes, the problem is not in using the
foreach
, but in defining the attributeid
of the element within the loop. This would create several elements on the page with the sameid
and that is not possible becauseid
is unique.– Woss
But with Class did not give either... I applied the class and put to search in the class but does not return, always returns 1, which is the first ID
– Sr. André Baill
You can update the question code if you want. Also search to do a [mcve].
– Woss
I suggest also including the ajax code you are using
– Isac