0
I need you to click on checkbox, he makes a database query and returns it to me inside a div. But I can pull the data with ajax and show in div directly(home_.php is showing the select I did), but when joining the ajax click event, I can’t get anything.
-By clicking on the checkbox, it will consult the BD,and show me the result in the div, will be flexbox.
HTML
<div id="conteudo">
RESULTADO:
</div>
<div class="checkboxes">
<input type="checkbox" id="regua">
<label for="regua">Régua</label><br>
<input type="checkbox" id="motor">
<label for="motor">Motor</label> <br>
<input type="checkbox" id="canal">
<label for="canal">Canal</label><br>
<input type="checkbox" id="fase">
<label for="fases">Fase</label><br>
<input type="checkbox" id="vigencia">
<label for="vigencia">Vigência</label>
</div>
JQUERY
<script src="jquery-3.4.1.js"></script>
<script type="text/javascript">
$("#regua").click(function(){
if($('#regua').is(':checked')){
}
});
</script>
AJAX
<script>
$.ajax({
url: "home_.php", // coloque aqui o endereço que vai buscar os dados no banco
success: function (data) {
$('#conteudo').html(data);
$('#conteudo').show(); // Mostrar o retorno em texto no html
},
error: function (request, status, erro) {
$('#conteudo').html('Ocorreu um erro, entre em contato com T.I!', erro);
$('#conteudo').show();
}
});
</script>
home_.php
<?php
include_once("./php/conect_postgre.php");
$consulta_bd = "SELECT * FROM uniao WHERE regua LIKE 'Co%'";
$result=pg_query($conexao, $consulta_bd);
if (($result)){
while($linha_usuario = pg_fetch_assoc($result)){
echo $linha_usuario['regua'] . "<br>";
}
}else{
echo "Nenhum resultado encontrado";
}
You have to put AJAX inside
if($('#regua').is(':checked')){
. Another thing, the script$("#regua").click(function(){
has to come at the end of thebody
.– Sam
I changed as said, and even clicking, does not return me the data, when ajax ta alone pulling, brings normally.
– CodeGirlLB
Put the script at the end of
body
?– Sam
yes put, it would be before the </body> right?
– CodeGirlLB
Yeah. Put a
alert("ok");
inside the if to see if it is calling.– Sam