-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (35 loc) · 1.12 KB
/
script.js
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
29
30
31
32
33
34
35
36
37
38
39
var apiURL = "https://en.wikipedia.org/w/api.php?callback=?";
$(document).ready(function() {
$('#searchSubmit').click(function() {
$("#display-result").empty(); // clear prior search results
$.getJSON(apiURL, {
action: 'query',
format: 'json',
inprop: "url",
formatversion: 2,
generator: 'search',
gsrsearch: $("input").val(),
gsrwhat: "text",
prop: 'extracts|info',
exsentences: 3,
exintro: "",
explaintext: "",
exlimit: 20,
})
.success(function(response) {
console.log(response);
response.query.pages.forEach(function(resp) {
$('#display-result').append(
"<a href='" + resp.fullurl + "' target= '_blank'><div id='result' class='results'><h3>" + resp.title + "</h3><p = class='extract'>" + resp.extract + "</p></div>");
})
});
}); // search
$('#randomPage').click(function() {
}); // randomPage
// trigger submit on use of enter key
$("#input").keyup(function(event) {
if (event.keyCode == 13) {
$("#searchSubmit").click();
}
});
});