Search for data-id and Remove from database

0

I have 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'm passing id="delete-image" and also the data-id.

How can I recover the data-id? I did it as follows:

$('#confirma-deletar-imagem').on('show.bs.modal', function(e) {         
    var inf_id = $(this).attr('data-id');
});     

In this case it is returning nullo. When I click on the image, I open a modal confirmation ... And when I click, you should call Ajax to remove it. However, I do not even know how to call ajax to remove, after clicking on the button called delete-image-modal.

How can I do this?

    
asked by anonymous 25.07.2017 / 23:13

1 answer

1

I made a change in its function, and I inserted the part of calling the ajax.

<?php foreach($fotos_ingresso as $valor){ ?>
    <div id="fotos-listagem-imagem">
        <a href="javascript:void(0);" data-toggle="modal" data-target="#confirma-deletar-imagem" 
            data-href="#" data-id="<?php echo $valor->inf_id; ?>">
            <img src="<?php echo base_url('assets/uploads/interno_fotos/'.$valor->inf_tipo.'/'.$valor->inf_imagem); ?>" 
            class="img-responsive corte-imagem">
        </a>
    </div>
<?php } ?>

<hidden id="hiddenValue" />

<script>
    $(function()){
        $('#confirma-deletar-imagem').on('show.bs.modal', function(e) {         
            $("#hiddenValue").val() = $(this).attr('data-id');
        );

        $("#btnRemover").click(function(){
            var data = {
                id_img: $("#hiddenValue").val()
            };

            $.post( "ajax/delete.php", function( data ) {
                //aplicar seu retorno
            });
        });
    };
</script> 
    
26.07.2017 / 17:37