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

129
Views
Mostrar pantalla de carga hasta que los datos estén listos en ExpressJS

Estoy usando titiritero para raspar un sitio web de trabajo. Todo está funcionando hasta ahora.

 app.get('/', async (req, res) => { res.render('index', {text: 'This is the index page'}); })

Al enviar, el usuario es redirigido a un archivo ejs

 <body> <div class="container"> <input type="text" class="submit" id="city-input" placeholder="Submit City"> <button type="submit" onclick="submitCity()">Submit</button> </div> </body>

guión.js

 function submitCity() { const city = document.getElementById('city-input').value; const url = 'http://localhost:3000/api/germany/' + city window.location.href = url; console.log(city); }

índice.js

 app.get('/api/germany/:key', async (req, res) => { const city = req.params.key; const data = await scraper.scrapeData(city); await db.updateDB(data); await res.render('result', { data: data }); })

Entonces, cuando el usuario hace clic en enviar, puede tomar alrededor de 1-2 minutos hasta que la página de resultados esté lista. Quiero agregar una página/información de carga hasta que los datos se extraigan y estén listos para enviar.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar fetch para realizar la solicitud en segundo plano:

 function submitCity() { const city = document.getElementById('city-input').value; const url = 'http://localhost:3000/api/germany/' + city const response = await fetch(url); // make initial request const data = await response.json(); // wait for response body, then parse as json console.log(data); }

Y en el servidor, simplemente devuelva los datos a la solicitud:

 app.get('/api/germany/:key', async (req, res) => { const city = req.params.key; const data = await scraper.scrapeData(city); await db.updateDB(data); return res.json(data); });
over 4 years ago · Santiago Trujillo 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!