wiki page api demo

Published on Author adminLeave a comment

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js”></script>
<script>
$(document).ready(function(){

 

var search_string = “India”;

$.ajax({
type: “GET”,
url: “http://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text&section=0&page=”+search_string+”&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();
$(‘#article’).html($(blurb).find(‘p’));

},
error: function (errorMessage) {
}
});
});

</script>
<div id=”article”>

</div>

Leave a Reply