forked from sunilsj99/WikipediaViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwiki.js
More file actions
28 lines (25 loc) · 1.11 KB
/
wiki.js
File metadata and controls
28 lines (25 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$(document).ready( function() {
$('#searchForm').on('submit', function(e) {
$('#result').empty();
e.preventDefault();
var search = $('#searchQuery').val();
$.ajax({
url: "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=" + search + "&prop=info&inprop=url&utf8=&format=json",
dataType: "jsonp",
success: function(data){
if(data.query.searchinfo.totalhits !== 0)
{
var title = [];
var desc = [];
for(var i = 0; i < data.continue.sroffset ; i++)
{
title.push(data.query.search[i].title);
desc.push(data.query.search[i].snippet);
var wiki = '<div class="jumbotron" id="box"><h3><a href="https://en.wikipedia.org/wiki/'+title[i]+'" target = "_blank">'+ title[i] + '</a></h3><h4>'+ desc[i] +'</h4></div>';
$('#result').append(wiki);
}
}
}
});
});
});