Ajax - after calling him my functions are not working

Asked

Viewed 54 times

0

Hi guys this is my first question so come on. I am developing a page for android where it counts with only js, html and jquery, I made a back that searches for information in the database from a way that sends this data to the php page, after that it loads in a table , but when loading the page at the very beginning it loads a select from an ajax as well. that code here

    function carregaform(){
          var url = "http://localhost/app2/www/phps/selecttr.php";
          $.getJSON(url,function(result){
          console.log(result);
          $.each(result, function(i, field){

                var id = field.id_tr;
                var nome = field.nome_tr;
                $('#select').append("<option value=" + id + " class='opt'>" + nome + "</option>");
              }

          );
        }
       );
      }

and after I call the second part of the code that is the search to insert the results into the table it no longer works this function of loading the form(carregaform()) and nor other functions that I created. The function I created to carry the information.

function valida_form(){
                var src = formulario.src.value;
                var empre = formulario.select.value;

                        if(src.length == "" ){
                            formulario.src.focus();
                            return false;
                       }
                        else if(empre.length == ""){
                            formulario.src.focus();
                            return false;
                       }
                        else{

                            $.ajax({
                            type: "GET",
                            url: "http://localhost/app2/www/phps/conecta.php",
                            dataType: 'json',
                            data: {src:src, select:empre},
                            success: function(retorno){

                                var hashes = retorno.split('&');
                                if(hashes.length > 2){
                                    for(var i = 0;i < hashes.length; i++){

                                    var titulo = decodeURI(getUrlTitulo(retorno)[i]);

                                    for(z=0;z < titulo.length;z++){
                                        titulo = titulo.replace("_"," ");
                                    }
                                        var conteudo = decodeURI(getUrlConteudo(retorno)[i]);
                                        var conteudo2 = conteudo.replace(/[\\"]/g,'');
                                        $("table").append("<tr id='t_titulo'>" + "<th>" + titulo + "</th>" + " </tr><td id = 't_conteudo'> " + conteudo2 + "</td>" + "</tr>");
                                    }

                                }
                                else{
                                    alert("Não ha nenhum produto cadastrado com este codigo");
                                    window.location.reload();
                                }
                            },
                            error: function(){
                                alert("Erro ao conectar com o arquivo, favor contatar o suporte");

                            }

                     });

                }  

I’ve tried some things but it wasn’t like for example: At the end of the code

if(true){
                   carregaform();
                    ativa_botao_map();
                }

however it just calls the active_boot.

  • In this passage <option value=" + id + " class='opt'> should contain simple quotes to assign the id <option value='" + id + "' class='opt'>

  • I will update and find out if the error perssiste. Thank you

  • Here " </tr><td id = 't_conteudo'> " gets like this: " </tr><td id='t_conteudo'> "

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.