Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Ajax Response JSON data to select box in html

below is my ajax call and i am getting r JSON data

$.ajax ({
            type: "POST",
            url: "getrecieverlist.php",
            data: { strSenderID: sendmeid },
            success: function (r) { 
            }
       });   

I am getting r response as JSON data below

{
 "receiverDetails": [
{
  "receiver_id": "55555",
  "name": "Nitin",
  "mobile": "7777777777",
  "ifsc_code": "IFSC54545",
  "acc_no": "16-01-2017"
},
{
  "receiver_id": "66666",
  "name": "Vikram",
  "mobile": "9191919191",
  "ifsc_code": "IFSC54545",
  "acc_no": "13-01-2017"
}
],
 "success": 1
 }      

and my select box html code is below

<select id="recieverlist" name="select" class="main-form">
      <option value="">None Selected</option>
    </select>

what i want is to populate select box options with text as name from the JSON data and value of the options to be receiverid, i tried many things but did not worked out for me need the proper guide how to do it?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Give a try on following.

success : function (r) {
    var data = r.receiverDetails;
    var options = '';

    for(var i=0; i<data.length; i++) { // Loop through the data & construct the options
        options += '<option value="'+data[i].receiver_id+'">'+data[i].name+'</option>';
    }

    // Append to the html
    $('#recieverlist').append(options);
}
over 4 years ago · Santiago Trujillo Relatório

0

You can also $.each function.

                $.each(data.receiverDetails, function(index, value)
                    $("#recieverlist").append('<option value="'+value.receiver_id+'">'+value.name+'</option>');
                  });
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda