Reputation: 63
How can I use fetch method for AJAX with REST API? Any example please.
I try to use
fetch('https://jsonplaceholder.typicode.com/posts').then( (r) => console.log( r ));
And did not get JSON as expected.
Upvotes: 4
Views: 1055
Reputation: 1308
You should convert the promise result in JSON. Try to use
fetch('https://jsonplaceholder.typicode.com/posts')
.then( (r)=> r.json() )
.then( (r) => console.log( r ));
Upvotes: 1