Modal bootstrap does not open according to dynamic link

0

I have a listing in PHP / Mysql of which I open in a modal window the description of a particular product. The code is as follows:

Page list-products.php

while($jm = mysqli_fetch_object($sql)){
  $listar = "<a href=\"ver-produtos.php?Key=".$jm->IdCodProdutos."\" data-toggle=\"modal\" data-target=\"#myModal\" class=\"btn btn-xs btn-primary\">Ver currículo</a></div>";
}

Modal

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <div class="modal-dialog">
           <div class="modal-content">

           </div>
           <!-- /.modal-content -->
     </div>
     <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

Ver-products.php page

// teste
echo $_REQUEST['Key'];

The window opens correctly, however it is necessary to update the product listing page to get the other Key.

    
asked by anonymous 02.06.2015 / 15:25

1 answer

2

The modal maintains the contents of the first request, so the first one you open will be permanent until you reload the page.

To fix the problem, create an alternate toggle that resumes loading.

$(document).on('click', "[data-toggle='meumodal']", function(event){
  event.preventDefault();
  target = $(this).attr("data-target");
  content = $(this).attr("href");
  $(target+".modal .modal-content").load(content,function(){
     $(target).modal('show');
  });
});

And use your links

while($jm = mysqli_fetch_object($sql)){
  $listar = "<a href=\"ver-produtos.php?Key=".$jm->IdCodProdutos."\" data-toggle=\"meumodal\" data-target=\"#myModal\" class=\"btn btn-xs btn-primary\">Ver currículo</a></div>";
}
    
02.06.2015 / 16:17