forked from COLTEC-DAW/TP-RESTFul-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
66 lines (59 loc) · 2.21 KB
/
app.js
File metadata and controls
66 lines (59 loc) · 2.21 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Grupo: Thales Eduardo, Artur Gonzaga, Bernardo Oliveira
*/
function listarRecursos() {
document.getElementById("resources").style = "display: grid;";
document.getElementById("resources").innerText = " ";
$.ajax({
url: 'https://api.chess.com/pub/player/thalesed',
type: 'GET',
dataType: 'json',
success: function (data) {
// Manipule os dados conforme necessário para listar os recursos desejados
var resources = Object.keys(data);
// Exiba os recursos na sua página HTML
var resourcesList = $('#resources');
resources.forEach(function (resource) {
resourcesList.append('<li><button class="butRes" onclick="buscarRecurso(this.innerText);">' + resource + '</button></li>');
});
},
error: function () {
$('#error').show();
$('#resources').hide();
},
complete: function () {
console.log("request completed");
}
});
}
function buscarRecurso(recurso) {
if(recurso == null){
recurso = document.getElementById("recurso").value;
}
document.getElementById("resources").style = "display: none;";
$.ajax({
//url: 'https://anapioficeandfire.com/api/characters/583',
url: 'https://api.chess.com/pub/player/thalesed',
dataType: 'json',
success: function (data) {
// Verifica se o recurso fornecido existe nos dados
$('resources').hide();
if (data[recurso] !== undefined) {
// Exibe o recurso na sua página HTML
$('#result').html('<p style="max-width: 300;">' + recurso + ': ' + JSON.stringify(data[recurso], null, 2) + '</p>');
$('#error').hide();
} else {
// Se o recurso não for encontrado, exibe uma mensagem de erro
$('#result').empty();
$('#error').show().text('Recurso não encontrado');
}
},
error: function () {
$('#error').show().text('Erro na requisição');
$('#result').empty();
},
complete: function () {
console.log("request completed");
}
});
}