Ep

Ep

Wikipedia API Example JavaScript Code

Wikipedia API Example Json

This blog post demonstrates wikipedia api example search using jQuery. Wikipedia api is a web service that provides access to wiki features and data using Http request. Find the wikipedia api example javascript code snippet below :-
wikipedia api call example,wikipedia api example,wikipedia api example c#,wikipedia api example html,wikipedia api example javascript,wikipedia api example json,wikipedia api example of,wikipedia api example search
wikipedia api query example
Demo.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Wikipedia API Call Example</title>
    <script src="jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#txtSearchText').keypress(function (e) {
                if (e.keyCode == 13)
                    $('#btnSearch').click();
            });
        });

        function WikipediaSearchAPI() {
            var txt = $("#txtSearchText").val();

            $.ajax({
                type: "GET",
                url: "http://en.wikipedia.org/w/api.php?action=opensearch&search=" + txt + "&callback=?",
                contentType: "application/json; charset=utf-8",
                async: false,
                dataType: "json",
                success: function (data, textStatus, jqXHR) {
                    $.each(data, function (i, item) {
                        if (i == 1) {
                            var searchData = item[0];
                            WikiDataAccess(searchData);
                        }
                    });
                },
                error: function (errorMessage) {
                    alert(errorMessage);
                }
            });
        }

        function WikiDataAccess(search) {
            $.ajax({
                type: "GET",
                url: "http://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text&section=0&page=" + search + "&callback=?",
                contentType: "application/json; charset=utf-8",
                async: false,
                dataType: "json",
                success: function (data, textStatus, jqXHR) {

                    var markup = data.parse.text["*"];
                    var blurb = $('<div></div>').html(markup);

                    // remove links as they will not work
                    blurb.find('a').each(function () { $(this).replaceWith($(this).html()); });

                    // remove any references
                    blurb.find('sup').remove();

                    // remove cite error
                    blurb.find('.mw-ext-cite-error').remove();
                    $('#results').html($(blurb).find('p'));
                    $('#results').html(blurb);

                },
                error: function (errorMessage) {
                    alert(errorMessage);
                }
            });
        }
    </script>
</head>
<body>
    <div>
        <p>
            <h1>Wikipedia API Example</h1>
        </p>
        <input id="txtSearchText" type="text" value="asp.net" />
        <input id="btnSearch" type="button" value="Search" onclick="WikipediaSearchAPI();" />
    </div>
    <br /><br />
    <div id="results" style="width:700px; height:550px; overflow:auto; font-family:Verdana; font-size:11px; ">

    </div>
</body>
</html>
Wikipedia API Example JavaScript Code Reviewed by Ravi Kumar on 12:42:00 AM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.