Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda