0
I have a URL that returns data in JSON:
[
{
"id": 21,
"solicitante": "Joao",
"chamado": "coisa aqui no lab"
},
{
"id": 22,
"solicitante": "Maria",
"chamado": "projetor deu pau"
}
]
On another page, on the same domain, I try to use the API fetch
to request the data:
fetch("http://" + window.location.host + "/list/", {method: 'GET'})
.then(function(res){
console.log(res.json())
res.map(function(item){
console.log(item)
});
});
However, the console.log(res.json())
prints the following:
Promise {<resolved>: Array(2)} __proto__: Promise [[PromiseStatus]]: "resolved" [[PromiseValue]]: Array(2) 0: {id: 21, solicitante: "Joao", chamado: "coisa aqui no lab"} 1: {id: 22, solicitante: "Maria", chamado: "projetor deu pau"} length: 2 __proto__: Array(0)
And when I try to use the Array.prototype.map
, get this error:
Uncaught (in promise) TypeError: res.map is not a function at <anonymous>:4:6
As disassembled above, I am unable to access the answer data.