0
I have more than 50 checkbox,when I click on it, it checked the state with jquery step pro ajax bring the data from the page "home.php", but the way it is like this, I have to duplicate the code and change the id dos checkbox pro ajax go on select page bring me the return and ta leaving my huge index. I would like a solution, I don’t know much about ajax, but I want a single ajax code that will receive the values checked and make the request. Instead of duplicating the ajax and changing the id.
Jquery and AJAX
<script src="jquery-3.4.1.js"></script> 
            <script type="text/javascript">
                 $("#cartao").click(function(){
                         if($('#cartao').is(':checked')){
                            $.ajax({
                                url: "php/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
                                      $.each(data, function (i, element) {
                                        $('#conteudo').html(element.linha_usuario); // ou assim
                                     });
                                }
                            });
                           }
                     });
            </script>
            <script type="text/javascript">
                 $("#consorcio").click(function(){
                         if($('#consorcio').is(':checked')){
                            $.ajax({
                                url: "php/select_conso.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
                                      $.each(data, function (i, element) {
                                        $('#conteudo').html(element.linha_usuario); // ou assim
                                     });
                                }
                            });
                           }
                     });
            </script>
ajax has to come in index? I can’t have these files in a folder called 'js' and call it in as a function and load along with the page?
– CodeGirlLB
You can as you wish. You can create a file
.jsand load. All you have to do is adjust the path to the . php files in AJAX.– Sam
You’re not going, when I click it doesn’t bring me back
– CodeGirlLB
I’ll put it on the github for you to see
– CodeGirlLB
https://github.com/lauradevcode/bb_template put it all together so I can see where I’m going wrong
– CodeGirlLB
There’s a mistake on this line:
url: "php/"home_ + this.dataset.url +".php",... should beurl: "php/"+ this.dataset.url +".php",if the . php files are in a "php/" subfolder... if they are in the same folder should beurl: this.dataset.url +".php",– Sam
If I want to separate, when it shows in the div, it loads all the 'card' records, but I want each line to appear in a separate flexbox, how can I do that? In case I want the record of the first line to appear in the first div, then I open another div off and the second record enters there and so on...
– CodeGirlLB
That’s another question and there’s no way I can explain it here. :/
– Sam