Zafir Stojanovski
Zafir Stojanovski

Reputation: 481

Reading data from JSON reply with JQuery

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?

Upvotes: 1

Views: 53

Answers (2)

Ali Baig
Ali Baig

Reputation: 3867

Try using

data["ISBN:"+key]

Where key is the key you are passing to the function

Upvotes: 1

Zafir Stojanovski
Zafir Stojanovski

Reputation: 481

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.

Upvotes: 0

Related Questions