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

156
Views
Obtenga JSON con PHP desde la URL y entrégueselo a JS

Estoy atascado en un problema. Lo que quiero hacer es obtener un archivo JSON de una URL usando PHP (para superar el problema de CORS cuando se usa AJAX) y luego usar JSON.parse para que JavaScript pueda usarlo para hacer una lista del contenido JSON.

Probé este código antes pero no funciona.

 <!DOCTYPE html> <html> <head> <title>Beispiel</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <?php $url = "http://geoweb.zamg.ac.at/static/event/lastday.json"; ?> <script> var array = JSON.parse(<?php file_get_contents($url) ?>); console.log(array); </script> </body> </html>

Tal vez alguien de ustedes pueda ayudarme con ese problema. Todavía no soy muy bueno programando ;)

¡Muchas gracias de antemano!

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

0

No necesita JSON.parse() , porque el JSON ya se analizó desde el origen del archivo.

También te perdiste hacer echo del retorno de file_get_contents().

 var array = <?php echo file_get_contents($url) ?>; console.log(array);
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!