-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
40 lines (40 loc) · 1.67 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
$(document).ready(function () {
$('#searchForm').submit(function (e) {
e.preventDefault();
var searchText = $('#search').val();
var table = $('#myTable');
var tableBody = table.find('tbody');
var errorField = $('.errorFiled')
var errorText = errorField.find('span');
tableBody.html('');
if (searchText.trim() != '') {
$.getJSON('https://api.publicapis.org/entries?title=' + searchText, function (result) {
if (result.count) {
errorField.hide();
table.show();
$.each(result.entries, function (key, value) {
console.log(value.Auth);
value.Auth = (value.Auth == '') ? "No" : value.Auth;
tableBody.append(
"<tr>" +
"<td>" + value.API + "</td>" +
"<td>" + value.Description + "</td>" +
"<td>" + value.Auth + "</td>" +
"<td>" + value.HTTPS + "</td>" +
"<td>" + value.Category + "</td>" +
"<td>" + value.Cors + "</td>" +
"<td>" +
"<a href='" + value.Link + "' target='_blank'>Go</a>" +
"</td>" +
"</tr >"
);
});
} else {
table.hide();
errorField.show();
errorText.html('').html(searchText)
}
});
}
});
})