-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
29 lines (28 loc) · 963 Bytes
/
main.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
$(document).ready(function () {
$('#search'). on('click', function () {
var content = $('#content').val();
var url = 'https://en.wikipedia.org/w/api.php?action=opensearch&search=' + content + '&format=json&callback=?';
$.ajax({
url: url,
type: 'GET',
async: false,
dataType: 'jsonp',
success: function (response) {
console.log(response);
$('#display'). html(''); //clears exist data before loop
for (var i = 0; i < response[1].length; i++) {
$('#display').append("<a href=" + response[3][i] + " target='blank'><h1>"
+ response[1][i] + "</h1></a>" + "<h3>" + response[2][i] + "</h3><br>");
}
},
error: function (errorMessage) {
alert('Error');
}
});
});
$('#content').keyup(function (event) {
if (event.keyCode === 13) {
$('#search').click();
}
});
});