0

The URL below responds with a .txt file in web browser. How would I console.log() the data inside .txt file using Fetch API in JavaScript?

Here abovementioned URL:

http://google.com/complete/search?client=chrome&q=python

The promise is fulfilled but i didn't find a way to get the data inside .txt file

fetch("http://google.com/complete/search?client=chrome&q=python", {
      method: 'GET',
      mode: 'no-cors',
      headers: {
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582',
      'Content-Type': 'text/plain',
      },
    })
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Shubham Negi
  • 57
  • 1
  • 1
  • 4
  • Did you check the [documentation](https://developer.mozilla.org/en-US/docs/Web/API/fetch)? – JavaScript Apr 05 '22 at 07:45
  • From the duplicate, on the subject of `no-cors` mode: **Note that this won't let you do anything that you require CORS to do. You will not be able to read the response.** – Quentin Apr 05 '22 at 09:27
  • Why are you overriding the `User-Agent` header? – Quentin Apr 05 '22 at 09:28
  • Why are you setting a `Content-Type` of `text/plain` when you are making a GET request so you aren't sending any content at all (plain text or otherwise)? – Quentin Apr 05 '22 at 09:28
  • That URL returns JSON, not plain text. – Quentin Apr 05 '22 at 09:31

0 Answers0