0
I am making a div with form to be hidden, and using AJAX for when it is clicked on the search button div is visible, and brings the result of the database in PHP. Only that I just can’t put my chunk of the table div to be shown in AJAX...the logic of the code is.. I have combobox that is visible, when selecting the value 'Boletos' it shows the div1, selecting a value in the div1 and clicking the search button it remained visible and should bring the result of the table div...my code is like this:
$(document).ready(function() {
$('#div1').hide();
$('#comboBox').change(function() {
if ($('#comboBox').val() == 'Boletos') {
$('#div1').show();
acao = '#form_1';
form = '#div1';
}
$(document).on('click', '.botao', function(e){
e.preventDefault();
$.ajax({
url: acao,
type: "post",
data: $(form).serialize(),
complete: function (response) {
//AQUI ela deveria trazer a minha div TABELA com o resultado do banco
$('#tabela').html(Visibility='visible');
$('#div1').show();
},
error: function () {
$('#tabela').html('Erro, não há resultados');
},
});
});
});
My POST method is to do the whole process on this same page.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<select id="comboBox" name="comboBox">
<option>Selecione sua opção aqui</option>
<option value='Boletos'>Boletos</option>
<option value='Folhas'>Folhas</option>
<option value='Guias'>Guias</option>
</select>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" id="form_1" method="POST">
<div id="#div1">
<select id="combo1" name="combo1">
<option>Selecione sua opção aqui</option>
<option value='Pagamento 1'>Pagamento 1</option>
<option value='Pagamento 2'>Pagamento 2</option>
</select>
<button type="submit" class="botao" id="btn1" value="btn1">Buscar</button>
</div>
</form>
And here my div TABLE, which should be showing her result in AJAX:
<div id="tabela" class="table table-responsive">
<table class="nome>
<thead>
<tr>
<td><center>Protocolo</center></td>
<td><center>Boleto</center></td>
<td><center>Categoria</center></td>
</tr>
</thead>
<tbody>
<?php
include "conexao.php";
ini_set('max_execution_time', 600);
$categoria = $_POST['combo1'];
$stmt = $db->prepare("select protocolo,nomeBoleto,categoria,hr_dt_inserido from boletos WHERE categoria=$categoria");
$stmt->execute();
while($row = $stmt->fetch()){
if($row > 0){
?>
<tr>
<td><?php echo $row['protocolo']?></td>
<td><?php echo $row['nomeBoleto']?></td>
<td><?php echo $row['categoria']?></td>
</tr>
<?php
}
else{
echo "Não exitem Boletos a serem exibidos";
}
}
?>
</tbody>
</table>
</div>
I tested everything is working the only thing I need is in this excerpt of AJAX code I need to bring the result of my table div, which instead brings the word 'Visible':
complete: Function (Sponse) {
//AQUI ela deveria trazer a minha div TABELA com o resultado do banco
$('#tabela').html(Visibility='visible');
$('#div1').show();
},
Your code worked, but I have two more invisible Ivs that are no longer invisible.. in this section: 'var acao, form; $('#div1'). Hide(); $('#div2'). Hide();//These two Divs are no longer invisible $('#div3'). Hide();'
– Joana
But in your question there is no #div2 or #div3.
– Sam
I did not put to simplify...but anyway mto thank you aee.. if you can help thank you.. vlws
– Joana
Hi Joana. I would like to help yes.
– Sam