如何通过 REST API 使用 AJAX 的获取方法? 请举个例子。
我尝试使用
fetch('https://jsonplaceholder.typicode.com/posts').then( (r) => console.log( r ));
并没有像预期的那样得到 JSON。
最佳答案
您应该将 promise 结果转换为 JSON。尝试使用
fetch('https://jsonplaceholder.typicode.com/posts')
.then( (r)=> r.json() )
.then( (r) => console.log( r ));
关于javascript - 如何将 fetch 与 REST API 结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42277757/