0

When I access the URL directly, I see the JSON but I am getting an error when using 'fetch' to get the data. The error states that uncaught v in promise.

fetch('http://openlibrary.org/api/books?bibkeys=ISBN:157322359X&jscmd=data')
.then((resp) => {
    return resp.json()
})
.then((data) => {
    console.log(data);
})
1
  • The content of your url is like 'var _OLBookInfo = { ... }'. It is not json but text. JSON must contain no 'var _OLBookInfo = '. Commented Dec 28, 2019 at 22:00

2 Answers 2

1

Change your code to the following and it will work. I have just added a paramater key format with json value.

fetch('http://openlibrary.org/api/books?bibkeys=ISBN:157322359X&jscmd=data&format=json')
.then((resp) => {
    return resp.json()
})
.then((data) => {
    console.log(data);
})
Sign up to request clarification or add additional context in comments.

Comments

0

You are receiving this error because at the JSON endpoint you don't have pure JSON, you have JavaScript. That's why it's complaining about a 'v', because it has to be JSON.

You should just remove the var ... = on the endpoint

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.