-1
Well, I can bring you data from the bank using ajax, but I want you to click on input of the kind checkbox, he performs the database query and shows me the data inside a flexbox. I have 10 checkbox, with different names and loaded different data, and when clicking on the checkbox 'water', he performs the consultation in the bank and bring me on the screen everything water (carrying every kind of ruler in each flexbox). However the data comes in ajax, and I can also pull in jquery, but I want it to come right after the checked, I created the code already checking the checked of each input but after that I do not know how to perform the query to the bank in the same code, so I put the Alert to see if it works.
CONCLUSION:
- I want to CLICK the checkbox, make a BD query, and bring me that information, inside the flexbox.
HTML
<div id="conteudo">
<div class="flex">REGUAS:</div>
</div>
<div class="checkboxes">
<input type="checkbox" id="regua" onclick="checkFiltros()" name="check">
<label for="regua">Régua</label><br>
<input type="checkbox" id="motor" onclick="checkFiltros()" name="check">
<label for="motor">Motor</label> <br>
<input type="checkbox" id="canal" onclick="checkFiltros()" name="check">
<label for="canal">Canal</label><br>
<input type="checkbox" id="fase" onclick="checkFiltros()" name="check">
<label for="fases">Fase</label><br>
<input type="checkbox" id="vigencia" onclick="checkFiltros()" name="check">
<label for="vigencia">Vigência</label>
</div>
Jquery
$("#regua").click(function(e) {
if($(this).prop("checked") === true){
alert("O alerta está funcionando.");
});
)};
$("#motor").click(function(e) {
if($(this).prop("checked") === true) {
alert("O alerta está funcionando.");
}
});
$("#canal").click(function(e) {
if($(this).prop("checked") === true) {
alert("O alerta está funcionando.");
}
});
$("#fase").click(function(e) {
if($(this).prop("checked") === true) {
alert("O alerta está funcionando.");
}
});
$("#vigencia").click(function(e) {
if($(this).prop("checked") === true) {
alert("O alerta está funcionando.");
}
});
</script>```
PHP
<?php
include("./php/conect_postgre.php");
$consulta_bd = "SELECT * FROM uniao";
$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";
}
Thanks! It worked!
– CodeGirlLB
I touched something and it went wrong again.
<script>
 $(".checkboxes :checkbox").click(function(){ 
 // envia o id para a função se o checkbox estiver checado
 if(this.checked) retornConsult(this.id); 
 
 });
 </script>
– CodeGirlLB
<script>
 function retornConsult(){
 
 $.ajax({
 url: "home_.php",
 method: "post",
 data: { buscar: id},
 
 }); 
 success: function(data){
 $("#conteudo .flex").html(data);
 }
 }
 }
 </script>
– CodeGirlLB
I forgot to tell you, but you have to take the onclick off all the checkboxes
– Sam
I took it, but when I click, I don’t get the BD data back
– CodeGirlLB
That Ajax you showed there is wrong.
– Sam
what is wrong?

<script>
 function checkFiltros(dado){

 $.ajax({
 url: "home_.php",
 method: "post",
 data:{ 
 buscar: dado,
 
 }); 
 }
 success: function(data){ 
 $(".container").html(data);
 }
 }
 }
 </script>
– CodeGirlLB
The
success
has to be inside the$.ajax({});
– Sam
Is that right now?? <script> Function checkFilters(given){ $.ajax({ url: "home_.php", method: "post", data:{ search: checkbox, Success: Function(data){ $("#content . flex"). html(data); } } } });
– CodeGirlLB
It’s still wrong. That’s how it is:
function checkFiltros(dado){
 $.ajax({
 url: "home_.php",
 method: "post",
 data:{ buscar: dado},
 success: function(data){
 $("#conteudo .flex").html(data);
 }
 });
}
– Sam
THIS TA SCRIPT OK??? <script> $(".checkboxes :checkbox"). click(Function(){ // sends the id to the function if the checkbox is checked if(this.checked) checkFilters(this.id); }); </script>
– CodeGirlLB
All right....
– Sam