Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
¿Cómo puedo hacer que los elementos de este archivo JSON se muestren correctamente?

Así que no estoy seguro de lo que estoy haciendo mal aquí. Tengo estos tres elementos de un servicio y está en formato JSON. Cuando escribo el ciclo para mostrar solo el nombre del artista y la canción, sigo recibiendo un error

Este es el comando API en server.js

 app.post('/process_form', function(req, res){ var search = req.body.search axios.get('https://itunes.apple.com/search?term='+search) .then((response)=>{ var songlist = response.data.results; console.log(songlist); res.render('pages/thanks.ejs', { songlist: songlist, search: search }); }); })

Este es el código para el formulario html donde el usuario puede ingresar el nombre de una canción o artista

 <form action="/process_form" method="post"> <h1>Which song would you like to lookup</h1> <div> <input type="text" id="search" name="search"> </div> <input type="submit">

Y este es el formulario donde los resultados se mostrarán en una lista.

 <ul> <% songlist.forEach(function(songlist) { %> <li> <strong><%= songlist[artistName] %></strong> <strong><%= songlist[TrackName] %></strong> </li> <% }); %> </ul>

Así es como se ve la fuente original de los datos.

 { wrapperType: 'track', kind: 'song', artistId: 216123617, collectionId: 982317323, trackId: 982317327, artistName: 'Rockabye Baby!', collectionName: 'Lullaby Renditions of Radiohead', trackName: 'Let Down', },

Por último, el error que me sale es ese. Estoy confundido en cuanto a por qué dice que no definí la lista de canciones

 5| <main> 6| <ul> >> 7| <% songlist.forEach(function(songlist) { %> 8| <li> 9| <strong><%= songlist[artistName] %></strong> 10| <strong><%= songlist[TrackName] %></strong> songlist is not defined

Lo siento por la publicación larga. Estoy súper frustrado con esto y no sé qué estoy haciendo mal.

EDITAR: estoy usando EJS como motor de vista

app.set('ver motor', 'ejs');

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Encontré que la solución fue que cuando en realidad estaba procesando mi archivo de índice, puse

 res.render(index)

Cuando se suponía que el nombre del archivo era

 res.render(index.ejs)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!