Wikipedia Viewer - How to get Extracts

Hello World!

I’m having a problem trying to get the extract of a wiki page. From my understanding, I cannot search titles and get extracts in one ajax call; also I cannot make two ajax calls on one button click (unless its coded after\inside the other). My attempt so far is thus:
-query list of titles, store them
-get page ids from query, store them
-call second ajax at the end of success to:
-query using pageids to get extracts, store them (trouble here!)

Here is a link to the CodePen so far:
If I type in my browser I can view the ‘extracts’ content. This is what I want to access!

Usually in firefox console, on an output of apiResults, I can expand Object -> Query -> Search-> and see the array for ex. all titles, Ajax call using above url outputs Object -> Query -> Pages with no relevant information. (1)
Separating common wiki api access url and data results in the same output (2)
Querying just using pageid to access all key:values results in same output (3)
Using combinations of generator, exintro: true, prop: extracts results in same output

If any of this is false, there’s a better way to go about it, I’m not using the API correctly, any other insight, or point in the right direction would be much appreciated! Thank you

If you really want to get the extracts, then there’s technically no problem with making another AJAX call inside your first success handler. This is actually a very common pattern, though if you wanted to learn about promises you could simplify the code quite well. My suggestion is to seriously think about whether you need the extracts. In your first request, you get a response with snippets for each answer. Would the snippets suffice for your purpose?

The snippet[0] I was using to test on showed a bunch of links that I mistook for the “see all” wiki section. Snippets will work fine! So simple… Thank you!

1 Like

I was trying to do the same thing (because the sample product seemed to be using extracts) and I found that I can get search results and their extracts in 1 call by using the “generator” feature.

My code: