0

I have a flask server running that provides me with a JSON message when I manually visit 127.0.0.1:5000/data/get_data. CORS is disabled in this flask server and in my fetch-request I added {mode: 'no-cors'} as well.

Whenever I use the fetch-request in javascript, the response is empty while Flask tells me the GET request was heard and a response was sent. Flask gives me the exact same output when I manually request the data (and I can view the received JSON in the browser).

This is the javascript code to do the fetch-request

fetch('http://127.0.0.1:5000/data/get_data', {
    mode: 'no-cors'
})
.then(response => console.log(response));


FLASK clearly gets the request and sends a response:
this image is the INFO message from FLASK

this image is the HTTP response from FLASK

what the FETCH-request receives (logged in firefox dev-console)

I would love to know how I can receive the data that flask sends out, and keep it in a dictionary in javascript.

  • https://developer.mozilla.org/en-US/docs/Web/API/Response#Methods – Thomas Dec 11 '19 at 16:17
  • Does this answer your question? [Sending JSON response in Flask "POST" Route](https://stackoverflow.com/questions/62461923/sending-json-response-in-flask-post-route) – Jared Smith Jun 19 '20 at 11:49

1 Answers1

1
fetch('http://127.0.0.1:5000/data/get_data', {
    mode: 'no-cors'
})
.then(response => response.json())
.then(json => console.log(json));
jemiloii
  • 24,594
  • 7
  • 54
  • 83