Call Wikipedia API using jQuery

I decided to directly use the data from Wikipedia. Many pages contain a structured “Infobox” that I will use to gather information I need.

There is a Wikipedia API (more precisely, MediaWiki, the engine of Wikipedia, has an API). I invite you to read the documentation.

Here are some examples of what can be done using the javascript library jQuery:

It is important to note the needed “&callback=?” in the query (it will tell jQuery to use JSONP, a way to do cross-site javascript call), thanks to stackoverflow for this tip.

Note that to get the HTML content of a wiki page using javascript from the browser, I cannot use the “action=render” parameter of index.php because of the Same Origin Policy. I had to use the API to do it client side. I think I will rewrite my system to do this call server-side.

In the end, check my gist on github to get the full code of how to import a Wikipedia Page in javascript.