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

101
Vistas
How to return fetched and parsed xml through javascript function

I'm trying to make a simple html-page that shows now playing information from an in house media streamer. The streamer offers a status url that returns simple xml. I managed to fetch the xml, parse it and output it to the console log. But I can't get it to be shown in the html. Whatever I try, I keep seeing '[object Promise]'.

<script>
        let apis = {
            bluos: { //get bluos info
                api:"http://192.168.2.86:11000/",
                url: (status) => {
                    return apis.bluos.api + status
                }
            }
        };
        function getStatus() {
             return fetch(apis.bluos.url("Status"))
                .then(response => response.text())
                .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
                .then(data => console.log(data))   
        }
        document.getElementById("artist").innerHTML = getStatus();
        
    </script>

The parser seems to work, I see #document in the console log with parsed data:

Screenshot of the console log

I tried to first fetch and then return, but things like data and response are undefined.

        function getStatus() {
            fetch(apis.bluos.url("Status"))
                .then(response => response.text())
                .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
                .then(data => console.log(data));
               return data;
        }

I also tried:

function getStatus() {
                 fetch(apis.bluos.url("Status"))
                    .then(response => response.text())
                    .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
                    .then(data => console.log(data))  
                return document; 
            }

That returns [objectHTMLDocument]

Is that the way to go?

about 4 years ago · Juan Pablo Isaza
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