-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (31 loc) · 1.16 KB
/
Copy pathscript.js
File metadata and controls
36 lines (31 loc) · 1.16 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
29
30
31
32
33
34
35
36
//declare variables
var searchQuery;
var url;
//allows "enter/return" key to click search
$("#input").keyup(function(event) {
if (event.keyCode == 13) {
$("#search").click();
}
});
//search button
$("#search").on("click", function() {
$("#results").empty();
submit();
});
//function that runs when form is submitted
function submit() {
searchQuery = $("#input").val();
url = 'https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&titles=&utf8=1&srsearch=' + searchQuery + '&srlimit=15';
$.ajax({
url: url,
dataType: "jsonp", //indicates that its a jsonp request.
success: function(response) {
for (var i = 0; i < 15; i++) {
$("#results").append("<div class='box'></div>");
$(".box:last-child").addClass("animated fadeIn");
$(".box:last-child").append('<a class="title" target="_blank" href="https://en.wikipedia.org/wiki/' + response.query.search[i].title + '">' + response.query.search[i].title + '</a>');
$(".box:last-child").append('<p id="demo">' + response.query.search[i].snippet + '</p>');
}
}
});
}