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

77
Visualizações
passing data from loop to front-end

I have this function on my backend:

   app.get('/dashboard', async(req, res) => {
  const customers = await stripe.customers.list();

  customers.data.forEach(customer => {
    console.log(customer.metadata);
  });

  res.render('dashboard.ejs', {customer: customers})
})

and on my front end:

 <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
    <thead>
      <tr>
        <th>NAME</th>
        <th>EMAIL</th>
        <th>ACTIONS</th>
      </tr>
    </thead>
    <tbody>
      <% if(customer.length){ 
        for(var i = 0;i < customer.length;i++) { %>
      <tr>
      <td><%=customer[i].NAME%></td>
      <td><%=customer[i].EMAIL%></td>
         <% }
        }else{ %>
            <% } %>
    </tbody>
  </table>

however, i am trying to pass the METADATA to the front end. and within the metadata object, i have name and email. So on the front end, i tried:

<%=customer[i].METADATA.NAME%>

but it returned nothing. and same on the backend. how can i fix this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In the comments above, by fetch I mean the term fetch you need to some how connect to your backend to accept the data on front end. You can use ajax, axios, fetch API etc.... Below I used ajax to show how to get data from back end. Feel free to comment if you have any questions?

var data_from_backend;

$.ajax({
  type: 'GET',
  data: 'data_to_send_to_backend',
  url: 'server_URL',
  success: function(getMetadata) {
    $.each(JSON.parse(getMetadata), function(myMetadata) {
      data_from_backend = myMetadata.the_name_of_data_set_on_backend
    })
  },
  error: function(data) {
    console.log('Something went wrong.');
  }
});

console.log(data_from_backend)

about 4 years ago · Juan Pablo Isaza 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