Using Wikipedia Suggest API

In this post, I will explain how to use Retrieve Wikipedia Suggest Using JSON . Wikipedia Suggest API is free and simple to use. API is offered in XML and JSON. We will make use of jQuery UI autocomplete to build application.
URL for Wikipedia Suggest is:-http://en.wikipedia.org/w/api.php?action=opensearch&search=QUERY&limit=8&namespace=0&format=json&callback=?

(["a",["Animal","Association football","Australia","African American (U.S. Census)","Allmusic","Arthropod","Album","Actor"]])

The above is JSON response for Query=a. In URL we have specified callback=? for security purpose since jQuery does not allow cross domain request.
We can see that JSON response of Wikipedia Suggest is multidimensional array and jQuery autocomplete needs related suggest in array.

$(function(){
$( "#tags" ).autocomplete({
	source:function(request,response){
		$.getJSON('http://en.wikipedia.org/w/api.php?action=opensearch&search='+request.term+'&limit=8&namespace=0&format=json&callback=?',
		function (data)
		{
		 response(data[1]) 
	        });
          },
    autoFocus:true,
});

In demo i have shown a Wikipedia XML Search about which I will write in my next Article

You Might Also Like