i trying create modal pop , include ajax call inside modal body. script, included ajax. works fine.
here button calls modal (i working twig templates)
<button class="btn btn-danger" data-id="{{ product.id }}">delete</button> this jquery script:
$(document).ready(function() { $('[data-id]').each(function() { var $this = $(this), id = $this.data('id'); $this.on('click', function(event) { event.preventdefault(); $.post('{{ path('dashboard_ajax ') }}', { 'id': id }, function(details) { var $modal = $(details); $('#confirm-delete').remove(); $('body').append($modal); $modal.modal(); } ); }) }); }); and page modal
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="mymodallabel">confirm delete</h4> </div> <div class="modal-body"> <div class="alert alert-danger" role="alert"> <p>do want delete <b>{{ product.name }}?</b></p> </div> <img src="{{ asset('uploads/product_images/') }}{{ product.image }}" style="width: 240px;" class="img-responsive thumbnail" /> </div> <div class="modal-footer"> <button type="button" id="misha" class="btn btn-default" data-dismiss="modal">cancel</button> <a class="btn btn-danger btn-ok">delete</a> </div> </div> </div> now, if click on delete button remove selected item using related page (example: delete.php)
one way can attaching click hander , setting location this
window.location.href = 'delete.php'; or
<a class="btn btn-danger btn-ok" href="delete.php">delete</a> if have product id, sent delete.php
<a class="btn btn-danger btn-ok" href="delete.php?id={{ product.id }}">delete</a>
Comments
Post a Comment