-2

So I'm trying to get all the title links from a wikipedia page. I've successfully loaded the page in but I'm having trouble going through the JSON to get the titles. Here's the code I'm using. Can someone help?

$.ajax({
        url: "http://en.wikipedia.org/w/api.php?action=query&prop=links&format=json&plnamespace=0&pllimit=500&pldir=ascending&titles=The%20Settlers%20of%20Catan",
        dataType: "jsonp",
        success: function(data) {
        $.each(data.query.pages, function(i, item) {
            console.log(item.links.title);
            })
        }
    })

When this code runs I know it doesn't work. If I remove the "title" out of it, it'll give me a ton of "Objects" in the console and if I expand them I can see the title that I'm looking for but I'm just not sure how I can get that.

Thanks!

Vinny
  • 309
  • 3
  • 11

1 Answers1

2

links is an array (since there can be many links in a document).

You have to loop over it and deal with the title for each link in turn.

item.links[index].title
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335