Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!