Random Famous Quotes

免费增值
通过 Andres Olvera | 已更新 5 months ago | Data
人气

9.4 / 10

延迟

265ms

服务等级

100%

返回所有讨论

API not returning content

D
dgullifo
2 years ago

Using the JS fetch method, from inside html page, identical to the snippet.

This is what I get in the console:

Response {type: “cors”, url: “https://andruxnet-random-famous-quotes.p.rapidapi.com/?cat=famous&count=10”, redirected: false, status: 200, ok: true, …}
body: (…)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "https://andruxnet-random-famous-quotes.p.rapidapi.com/?cat=famous&count=10"
proto: Response

i.e. no valid response text. Any ideas what I am doing wrong? . Tks!

avatar
andruxnet commented 2 years ago

Are you using a GET request or a POST request? If it is a GET request, could you please share your code for me to try it?

D
dgullifo commented 2 years ago

OK so how do I share the code so that it will display correctly in this comment box? --It looks like the parser substitutes for all the <> and completely hides the javascript…

D
dgullifo commented 2 years ago

Update: the API return works when I add an extra promise to the fetch-based JS snippet:

})
.then(response => response.json()) << added to get the response to work as intended
.then(response => {
console.log(response);
})

I got the idea from this thread: https://stackoverflow.com/questions/33237200/fetch-response-json-gives-responsedata-undefined

avatar
payamazadi-natgeo commented 2 years ago

as i said earlier, add a user-agent header.

加入讨论 - 在下面添加评论:

登录/注册以发布新的评论
打分:4.6 - 投票:5