I'm Trying to send a GET req to my express server and logging it to the console using
const get = document.getElementById("getData");
get.addEventListener('click', getData)
const myRequest = new Request('/url here/', {
method: 'GET',
});
function getData () { fetch(myRequest)
.then(response => console.log(response))
};
but getting this(below) as the result and not the mongoose database array expected. what am i missing?
Response?{type: "basic", url: "url here", redirected: false, status: 200, ok: true,?…}body: (...)bodyUsed: falseheaders: Headers?{}ok: trueredirected: falsestatus: 200statusText: ""type: "basic"url: "url here/"__proto__: ResponsearrayBuffer: ? arrayBuffer()blob: ? blob()arguments: (...)caller: (...)length: 0name: "blob"__proto__: ? ()[[Scopes]]: Scopes[0]body: (...)bodyUsed: (...)clone: ? clone()formData: ? formData()headers: (...)json: ? json()ok: (...)redirected: (...)status: (...)statusText: (...)text: ? text()type: (...)url: (...)constructor: ? Response()Symbol(Symbol.toStringTag): "Response"get body: ? body()get bodyUsed: ? bodyUsed()get headers: ? headers()get ok: ? ok()get redirected: ? redirected()get status: ? status()get statusText: ? statusText()get type: ? type()get url: ? url()__proto__: Object
Here's the route:
router.route('/').get((req, res) => {
variable.find()
.then(variable => res.json(variable))
.catch(err => res.status(400).json('Error: ' + err));
});```
question from:
https://stackoverflow.com/questions/65880314/get-request-response-express-js 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…