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

224
Visualizações
Response text is always empty event when repose exist
  1. I am fetching the PDF via URL, and want to check does that URL will return the document successfully.

  2. Sending a request via fetch()

  3. Get a response.text()

  4. Want to check does text exist

  5. Text is always empty

Cannot figure out why?

response.text() always returns empty text, even when PDF document exist in response.


  const handleOpenPDF = (url: any) => {
    fetch(url, {
      method: 'GET',
      mode: 'no-cors',
    })
      .then(res => res.text())
      .then(text => {
    enter code here
        // TEXT is always empty event when response is good
        console.warn('text', text);

        window.open(url, '_blank');
      })
      .catch(err => {
        console.warn('Error', err);
      });
  };
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Note that res => res.text() means read the body as a string. So it is good idea to use response.json() before you access to response. something like this:

const handleOpenPDF = (url: any) => {
    fetch(url, {
      method: 'GET',
      mode: 'no-cors',
    })
      .then(res => res.json())
      .then(text => {
        console.warn('text', text);

        window.open(url, '_blank');
      })
      .catch(err => {
        console.warn('Error', err);
      });
  };

Also see this answer.

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