Execute jQuery to select Applicant

1

I have the following jQuery:

function clienteChange() {
    var id = $('#idCliente').val();
    $.ajax( 
    { 
        url:"/Administrar/clientes.endereco.php?id=" + id, 
        dataType : 'json', 
        success:function(result) { 
            $('[name^="cham_endereco[]"]').val(result.endereco); 
            $('[name^="cham_numero[]"]').val(result.numero); 
            $('[name^="cham_bairro[]"]').val(result.bairro); 
            $('[name^="cham_cidade[]"]').val(result.cidade); 
        } 
    }); 

    var selectSolicitante = jQuery(id).parents('tr').find('select.selectSolicitante');
    selectSolicitante.html('<option value="0">Carregando...</option>');
    $.post("/Administrar/clientes.solicitante.php?idCliente=" + id,
        {solicitante:jQuery(id).val()},
        function(valor){
            selectSolicitante.html(valor);
        }
    );
}

The first block works correctly, it shows the data right in the address, number ... I wanted to select the client, execute that first block but also execute the second block, searching for the prerequisite applicants ... I did the test, but does not work.

Follow PHP as well:

    mysql_query("SET NAMES 'utf8'");
    mysql_query('SET character_set_connection=utf8');
    mysql_query('SET character_set_client=utf8');
    mysql_query('SET character_set_results=utf8');

    echo "<option>teste</option>";

The signup screen is this:

    
asked by anonymous 08.08.2015 / 20:30

1 answer

1

Make sure your var selectSolicitante = jQuery(id).parents('tr').find('select.selectSolicitante'); command is actually returning the element you are looking for.

My suggestion is, if possible, to give a id or a class to your element, leaving your code like this:

    $(".selectSolicitante").html('<option value="0">Carregando...</option>');
    $.post("/Administrar/clientes.solicitante.php?idCliente=" + id,
        {solicitante:jQuery(id).val()},
        function(valor){
            $(".selectSolicitante").html(valor);
        }
    );

It's important to leave html(valor) because when your post returns the values you need, it will remove Loading from your select

    
08.08.2015 / 21:37