[英]How can I use fetch with REST API?
How can I use fetch method for AJAX with REST API? 如何在REST API中使用AJAX的fetch方法? 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. 而且没有按预期获得JSON。
You should convert the promise result in JSON. 您应该在JSON中转换promise结果。 Try to use
尝试使用
fetch('https://jsonplaceholder.typicode.com/posts')
.then( (r)=> r.json() )
.then( (r) => console.log( r ));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.