I've been having trouble accessing this piece of content in a json object. Here is my code for fetching data:
function getEntries(key){
$.ajax({
url: "https://openlibrary.org/api/books?bibkeys=ISBN:" + key + "&jscmd=details&callback=mycallback",
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
}
The reply I get looks like this: enter image description here
How do I access the pointed object if the key is different for every search?
asked Jan 21, 2017 at 15:46
Zafir Stojanovski
4917 silver badges19 bronze badges
-
data.ISBN not working ?Yashveer Singh– Yashveer Singh2017年01月21日 15:49:59 +00:00Commented Jan 21, 2017 at 15:49
-
No, but I found out that data.["ISBN:" + key ] does...Zafir Stojanovski– Zafir Stojanovski2017年01月21日 15:50:56 +00:00Commented Jan 21, 2017 at 15:50
2 Answers 2
Try using
data["ISBN:"+key]
Where key is the key you are passing to the function
answered Jan 21, 2017 at 15:50
Ali Baig
3,8574 gold badges36 silver badges49 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
I think I found it after all...
function getEntries(key){
$.ajax({
url: "https://openlibrary.org/api/books?bibkeys=ISBN:" + key + "&jscmd=details&callback=mycallback",
dataType: "jsonp",
success: function(data){
console.log(data["ISBN:"+key]);
}
});
}
did the trick.
answered Jan 21, 2017 at 15:50
Zafir Stojanovski
4917 silver badges19 bronze badges
2 Comments
trincot
So maybe use the extra 3 minutes to think it over before posting the question? ;-)
Zafir Stojanovski
You wouldn't believe me if I told you that I've been banging my head over this for the last 20 minutes. The answer flashed right after I clicked post.
lang-js