简体   繁体   中英

How can I use fetch with REST API?

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.

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 ));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM