Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
Get JSON with PHP from URL and hand it over to JS

i'm stuck at a problem. What i wanna do is to get a JSON file from a URL by using PHP (to overcome CORS issue when using AJAX) and then using JSON.parse to make it usable by JavaScript to make a list out of the JSON content.

I tried this code before but it isn't working.

<!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>

Maybe someone of you can help me with that problem. I'm not really good at programming yet ;)

Many thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't need to JSON.parse(), because the JSON is already parsed from the file source.

You also missed to echo the return of file_get_contents().

var array = <?php echo file_get_contents($url) ?>;
console.log(array);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda