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

116
Visualizações
Assigned fetched resource image url returns get error with local path

When attempting to assign the returned URL field of a JSON object retrieved from the NASA APOD API to a HTMLImageElement src property I receive a GET error. The error shows that the GET request appends a local file path before the external URL path.

Console logged as:

GET file:///C:/Users/username/OneDrive/Documents/Coding/NASA-POTD/Image%20of%20the%20day%20https://apod.nasa.gov/apod/image/2010/RhoAntares_Abolfath_1080.jpg net::ERR_FILE_NOT_FOUND

You can inspect my code below.

const sourceImg = document.getElementById('img');

const DATE = '&date=2020-10-14'

const RESOURCE = `https://api.nasa.gov/planetary/apod?api_key=hDhaSTsRNtw5sjymgxbwQDAfLGb7mDXcgxctq7xI${DATE}`;

fetch(RESOURCE)
.then(res => {
    if (!res.ok) { 
        errorReturned = true;
        throw new Error('error')
    };
    let reqBody = res.text();
    return reqBody
})
.then(reqBody => {
    let receivedRes = JSON.parse(reqBody)

    sourceImg.src = `Image of the day ${'https://apod.nasa.gov/apod/image/2010/RhoAntares_Abolfath_1080.jpg'}`
})

If anyone could help with the semantics of my question, I am a noob who doens't quite know how to word the question to understand the issue.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

By a serendiptous rewrite of the code I realize that you cannot have the HTMLImageElement.src property be set to a template literal.

Fixed with this:

sourceImg.src = 'https://apod.nasa.gov/apod/image/2010/RhoAntares_Abolfath_1080.jpg';
about 4 years ago · Juan Pablo Isaza Relatório
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