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

167
Views
Pase el archivo json al cliente usando rutas Express

Estoy tratando de enviar un archivo json al cliente, pero no puedo hacerlo. Recibo errores internos (500). ¿Alguien me puede ayudar? Además, uso Handlebars como motor de visualización.

aplicación.js:

 [...] var APIconditions = {}; var APIhourly = {}; function getWeatherData() { var data = ['/conditionsWU.json', '/hourlyWU.json']; request(data[0], function(err, res, body) { if (!err && res.statusCode == 200) { APIconditions = JSON.parse(body); } }); request(data[1], function(err, res, body) { if (!err && res.statusCode == 200) { APIhourly = JSON.parse(body); } }); } [...]

índice.js:

 [...] router.get('/conditions' , function(req, res, next) { res.json(APIconditions); }); router.get('/hourly' , function(req, res, next) { res.json(APIhourly); }); [...]

cliente.js:

 [...] function getWeather() { var APIconditions = 'conditions'; var APIhourly = 'hourly'; $.getJSON(APIconditions, function (data) { [...] }); $.getJSON(APIhourly, function (data) { [...] }); [...]
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No puede acceder a APIconditions o APIhourly desde otro archivo sin especificarlo.

La solución más simple sería adjuntarlos al alcance global, para que tenga acceso a ellos desde cualquier lugar.

 global.APIconditions = {} global.APIhourly = {}
about 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!