Help reading json from wikipedia api

Hi guys!

Turns out that I feel frustated doing the activity relative to wikipedia viewrs. My problem is that I can’t read any json coming from wikipedia.

I have read all the documents, and I have tried many different setups. I have also even copied the code of a guy which is all right, and it doesn’t work in my codepen.

I have activated the jquery framework as I have done in other practices. I don’t know what else to do and where to ask. If someone could help me, I would really appreciate it.

My code pen link is:

The part which is commented belongs to another unsucessfull attempt. The only thing I need is to read the json, I dont mind if it is for searching or another purpose.

Thank you in advance

I understand the frustration because the MediaWiki API is a lot denser than the ones used for the other challenges. I’m not sure if you’ve used the API sandbox, but it’s very useful:

As for this challenge, you need to use a generator, which returns search results. In the sandbox, select action as query. Then in the sidebar, select action=query. Also select format as JSON. (Do this in the API sandbox)

You’ll have a bunch of options in the query menu now. Since we want extracts of pages from our query, select the “prop” as “extracts”. However, what extracts do you want? To get this, scroll down to “Generator”, which will have a drop-down menu. Select “search”, as we want to search for a term and get results for it. Generators in the MediaWiki API return several pages depending on which property you want.

Now you’ll have two other options: generator and extracts. Since this is a project I’ll guide you to the appropriate links to use these properly.

For extracts:

For generator, don’t bother changing anything other than the limit. The gsrsearch field is the text you want to search. Look at the extracts article to know what to select. Once you’re done, you can get the correct api url and use it as usual with JQuery. Just use the sandbox and you’ll be ready in no time.


Thank you for your help, but I still have the same problem. The example I show in my codepen is copied from this website:


I think I got your ajax to actually run by wrapping it in it’s own function and calling it when you click the button. You still have to work on your api call so that it links to the right thing…but here’s the fork

Hope this helps :slight_smile:

1 Like

Ah, sorry for not reading your concern properly.

It works for me correctly if I place the container css assignment at the end of $(document).ready() function. I’m not really sure why, so I hope someone smarter sheds some light on this issue.

EDIT: Now it works without me modifying anything. Strange.I’d also recommend doing the “container-fluid” css assignment in a callback assigned to a “window.on(“resize”)” function

1 Like

thank you very much indeed both of you for helping me. I found out that my problem was to use the event.preventDefault() after the AJAX function. Now is before, where it should be, because It needs to stop the submit of the form otherwise I won’t get any result from the AJAX function.

So thank you again!!

1 Like

A server program that enables anyone to edit Web site content through their Web browser. Wikipedia provides an API to get page content search results.

Find the source code below consuming Wikipedia API example using Javascript Ajax Get

where on api you see prop and generator. dont confuse me.
every one use ajax… tsss and there wasn’t in lessons.
The stupid JSON format with no explanation. I see the structure like{ some;[ someone:[ [:datawant
I try everything. its diff as in weather application.I hate selfish programator whom don get someone one day use their inventions. there are everywhere easy examples, but don’t get it, how it works. how to get the content.
ar wiki = {
“batchcomplete”: true,
“query”: {
“pages”: [
“pageid”: 15580374,
“ns”: 0,
“title”: “Main Page”,
“revisions”: [
“contentformat”: “text/x-wiki”,
“contentmodel”: “wikitext”,
content”: "<!–

I follow strictly the wiki, the task is no complicated, but the people who doing the api, manuals etc…
There is no normal way even to steal code. I want to understand it. and the people who described the function ehm… there is nothing like open search in wiki main page or something there. I think that is something you dont want success students.
var s= $(“searchinput”)
$.get( “*&search="+s+"&format=json&meta=siteinfo&callback=&utf8=1&ascii=1&formatversion=latest&siprop=namespaces”,function(json, succes){





again where you see drop down menu?