Open In App
Related Articles

Autocomplete Search using jQuery and Wikipedia OpenSearch API

Like Article
Save Article
Report issue

In web design, the autocomplete feature is a common one. When the user types some value in the search text box, it automatically shows a relevant list of suggestions in the form of dropdown that can be chosen by the user easily. For jQuery Autocomplete feature, refer this article.

Approach: In this article, we use the Wikipedia Opensearch API and the jQuery Autocomplete UI. Basic HTML code is used for the user interface for keyword search in an input text box. While using the jQuery code, the search request is sent to Wikipedia which in turn returns a list of suggestions based on user entry. The data response is in JSON format.

Syntax: Wikipedia URL for API
Setting up environment: For more option settings

The developer can refer the above URL link and make use of many option settings depending on the application’s need.

jQuery and jQuery UI libraries: The following files are used in the code.

<link href=”” rel=”stylesheet” type=”text/css”/>
<script src=””></script> <script src=”””></script>

Example: The following example demonstrates the autocomplete search feature by using Wikipedia OpenSearch API and jQuery. The HTML code provides a normal search input box which gives suggestions when the user types some search texts.

<!DOCTYPE html>
    <script src=
    <link rel="stylesheet" href="
    <script src="
        body {
            width: 100%;
            background: #e9e9e9;
            margin: 0 auto;
            padding: 0;
            color: #7faf7f;
            font-family: Arial, sans-serif;
            font-size: 12px;
        #searchID input {
            width: 350px;
            height: 20px;
            margin: 0;
            padding: 15px;
            background: #fff;
            border: 1px solid black;
            color: #727272;
            float: left;
            font: 12px "Lucida Sans Unicode", sans-serif;
            transition: background 0.4s ease-in-out 0s;
        #searchID button {
            width: 45px;
            height: 45px;
            text-indent: -9999em;
            background: url("searchIcon.jpg") #4eac10;
            transition: background 0.3s ease-in-out 0s;
            border: 1px solid #fff;
        #containerID {
            width: 50%;
            margin: 0 auto;
        h2 {
            color: green;
            text-align: left;
    <div id="containerID">
                Autocomplete Search using jQuery
                and Wikipedia Opensearch API
            <form method="get" id="searchID">
                <input type="text" class="searchClass" 
                    id="searchInputID" value="" />
                <button type="submit">Search</button>
    <script type="text/javascript">
            source: function (request, response) {
                    // Wikipedia API url link
                    dataType: "jsonp",
                    data: {
                        action: "opensearch",
                        // Output format
                        format: "json",
                        search: request.term,
                        namespace: 0,
                        // Maximum number of result
                        // to be shown
                        limit: 8,
                    success: function (data) {


Last Updated : 21 Aug, 2020
Like Article
Save Article
Share your thoughts in the comments
Similar Reads