问题
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.
回答1:
fetch('http://127.0.0.1:5000/data/get_data', {
mode: 'no-cors'
})
.then(response => response.json())
.then(json => console.log(json));
来源:https://stackoverflow.com/questions/59289884/how-do-i-convert-a-requested-json-message-to-usable-data