I am trying to pass a variable to a modal, perform a query to give a return on html
, as the data will come in a formatted table. I tried some suggestions as alternatives, but I'm having trouble making the thing work, I have this line that invokes the modal:
<a href="#ModalDetalhes" data-toggle="modal" id="<?php echo $Eventos->IdEvento; ?>" data-target="#edit-modal"><?php echo $Eventos->Data; ?></a>
The script that will send the variable looks like this:
$('#edit-modal').on('show.bs.modal', function(e) { var $modal = $(this), IdEvento = e.relatedTarget.id; console.log("EVENTO: " + IdEvento); $.ajax({ cache: false, type: 'POST', url: 'pDetalhesEventos.php', data: 'IdEvento=' + IdEvento, dataType: 'html', success: function(data) { $modal.find('.edit-content').html(); } }); })
php is configured as follows:
require_once "../_classes/conexao_pdo.class.php"; require_once "../_classes/crud.class.php"; // Atribui uma conexão PDO $pdo = Conexao::getInstance(); // Atribui uma instância da classe Crud, passando como parâmetro a conexão PDO e o nome da tabela $crud = Crud::getInstance($pdo, 'cadEventos'); // DADOS DO FORMULÁRIO $IdEvento = (isset($_GET['IdEvento'])) ? $_GET['IdEvento'] : ''; // INICIALIZANDO O ARRAY $arrayParam = array(); // BUSCA COM FILTRO $sql = "SELECT *, DATE_FORMAT(Data, '%d/%m/%Y') as Data FROM cadEventos WHERE IdEvento = ?"; $arrayParam = array($IdEvento); $Resultado = $crud->getSQLGeneric($sql, $arrayParam, TRUE); $retorno = count($Resultado);
What I tried was to do this, passing the variable by url
retrieving by get
and post
:
url: "cliente.php?id=123",
The modal looks like this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><ahref="#edit-modal" data-toggle="modal" id="<?php echo $Eventos->IdEvento; ?>" data-target="#edit-modal">#Modal</a>
<div id="edit-modal" class="modal fade" 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">Detalhes do Evento</h4>
</div>
<div class="modal-body edit-content">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
The variable is correct because I can see it on the console.
Images from the FF console: