Popular type ["text"] by select

0

I'm trying to populate a type ["text"] through jquery and it's not working!

Form:

  <div>
        <label>Plano:</label>
        <select name="plano" id="plano" required>
             <?php echo $stringPlanos; ?>
        </select> <br /><br />
  </div>

  <div style="float:left">    
   <label class="labelPequeno">Valor</label><input type="text" class="real" style="width:100px; height:40px" required maxlength="23" id="valorCombinado"  name="valorCombinado" /> <br /><br />
  </div>    

jquery code

  <!-- INICIO ENTREGA VALOR DO PLANO -->
  <script src="http://www.google.com/jsapi"></script><scripttype="text/javascript">
  $(function(){
      $('#plano').change(function(){
          if( $(this).val() ) {
              $.getJSON('planos.ajax.php?search=',{cod_plano: $(this).val(), ajax: 'true'}, function(resultado){
                  var resultado = planosRetorno;
                  alert(resultado);
                  $('#valorCombinado').val(resultado).show();
              });
          } else {
              $('#valorCombinado').val('0.00');
          }
      });           
  });         
  </script>
  <!-- FIM ENTREGA VALOR DO PLANO -->

planes.ajax.php

<?php
 $cod_plano = mysql_real_escape_string( $_REQUEST['cod_plano'] );
 $planosBase = $PlanosDao->pesquisaPlanoEdicao($cod_plano);
 $planosRetorno = $planosBase->getValor();
 echo( json_encode($planosRetorno) );
?>

But the browser console does not show $ errors and the field is not populated!

Where am I going wrong?

    
asked by anonymous 26.09.2015 / 16:09

1 answer

1

Oops, friend, you're capturing the wrong variable in this code snippet:

          ...
          $.getJSON('planos.ajax.php?search=',{cod_plano: $(this).val(), ajax: 'true'}, function(resultado){
              var resultado = planosRetorno;
              alert(resultado);
              $('#valorCombinado').val(resultado).show();
          });
          ...

The result variable is capturing an erroneous value: return plans does not exist, return is actually result

If you are having trouble verifying the error of your request, try using the jquery ajax method:

$.ajax( "example.php")
    .done(function() {
        alert( "success" );
    })
    .fail(function() {
        alert( "error" );
    })
    .always(function() {
        alert( "complete" );
    });

( link )

    
27.09.2015 / 04:22