Ajax returning HTML next to Json

1

Hello,

I'm trying to fill in input data with the result of a search in the database using what I've typed before as a filter. ex: User type customer code and when you focus the input, all fields (name, phone, address) are already filled in

I did the below function using JQuery to return the search result done in PHP.

      $(document).ready( function() {
       /* Executa a requisição quando o campo CEP perder o foco */
       $('#txtCod').blur(function(){
               /* Configura a requisição AJAX */
               $.ajax({
                    url : 'busca_cliente.php', /* URL que será chamada */ 
                    type : 'POST',  
                    data: 'cod=' + $('#txtCod').val(), /* dado que será enviado via POST */
                    dataType: 'json', /* Tipo de transmissão */
                    complete: function(resposta){
                        //o problema começa aqui !!!
                        $('#txtNome').val(resposta.nome);
                        //console.log(resposta);
                    }
               });   
       return false;    
       })
    });

My problem is that in addition to returning the JSON from what I need, the code is returning an HTML snippet. God knows where, it follows what is returned.

 "<form style=display: inline; margin: 0px; padding: 0px; name=imprimecupom method=post target="_blank">
     <input type=hidden name=op>
     <input type=hidden name="pessoa">
     <input type=hidden name="tipo">
     <input type=hidden name="valorbruto">
     <input type=hidden name="horario">

  </form>


   {"cod_medico":"42","nome":"Guilherme","matricula":"122344","guia":"1","chave":"","senha":"","email":"","sexo":"","cidade":"","estado":"","contato":null,"cpf":"","espec":"","telefone":"","cep":"","endereco":"","cod_operadora":null}"

How to make it return only JSON, and if it is not, how to ignore the HTML and only use the JSON of the answer given by Ajax, because with that HTML too, I can not access the JSON to fill the inputs .

Thanks to all;

EDIT

Follow the client search code, however simple it may be

$cod = $_POST['cod'];
$sql   = "SELECT * FROM clientes WHERE cod_cliente = '{$cod}'";
$res   = mysql_query($sql, $db); 
$linha = mysql_fetch_assoc($res);
echo json_encode($linha);
    
asked by anonymous 06.09.2016 / 17:00

1 answer

0

The error was in the configuration file of the bank where it had a lost echo that returned the HTML.

    
12.09.2016 / 15:01