如何使用REST API获取?
问题描述:
如何使用REST API的AJAX提取方法? 请举例。如何使用REST API获取?
我尝试使用
fetch('https://jsonplaceholder.typicode.com/posts').then((r) => console.log(r));
并没有如预期得到JSON。
答
您应该在JSON中转换承诺结果。尝试使用
fetch('https://jsonplaceholder.typicode.com/posts')
.then((r)=> r.json())
.then((r) => console.log(r));