diff --git a/Unidad_05_Javascript/AccesoSimpleBackenAPI/accesoGenders.html b/Unidad_05_Javascript/AccesoSimpleBackenAPI/accesoGenders.html
index 72fdf34..a931d0a 100644
--- a/Unidad_05_Javascript/AccesoSimpleBackenAPI/accesoGenders.html
+++ b/Unidad_05_Javascript/AccesoSimpleBackenAPI/accesoGenders.html
@@ -11,29 +11,68 @@
const xhttp = new XMLHttpRequest();
xhttp.onload = function () {
- let strResponse = xhttp.responseText;
- console.log("Datos recibidos: " + strResponse);
- let jsonResponse = JSON.parse(strResponse);
- console.log("Datos parseados: " + jsonResponse);
- for (let i = 0; i < jsonResponse.length; i++) {
- let genero = jsonResponse[i];
- console.log("Género: " + genero.id + " - "
- + genero.nombre);
- gendersTable.innerHTML += '
' +
- '| ' + genero.id + ' | ' +
- '' + genero.nombre + ' | ' +
- '
'
+
+ if (xhttp.readyState === 4) { // 4 = La solicitud ha sido completada
+ if (xhttp.status === 200 || xhttp.status === 201) {
+ let strResponse = xhttp.responseText;
+ console.log("Datos recibidos: " + strResponse);
+ let jsonResponse = JSON.parse(strResponse);
+ let responseArray = jsonResponse.content;
+ console.log("Datos parseados: " + responseArray);
+ for (let i = 0; i < responseArray.length; i++) {
+ let genero = responseArray[i];
+ console.log("Género: " + genero.id + " - "
+ + genero.nombre);
+ gendersTable.innerHTML += '' +
+ '| ' + genero.id + ' | ' +
+ '' + genero.nombre + ' | ' +
+ '
'
+ }
+ }
+ else {
+ console.log('Error al obtener la petición xhr.status: ' + xhttp.status);
+ }
}
}
// Send a request
- xhttp.open("GET", "http://localhost:8081/v1/genders");
+ xhttp.open("GET", "http://localhost:8081/v1/genders?page=0&size=100&fieldOrder=id&orderType=desc");
xhttp.send();
}
+
+
+
+ function updateGender() {
+ const xhttp = new XMLHttpRequest();
+ xhttp.onload = function () {
+
+ if (xhttp.readyState === 4) { // 4 = La solicitud ha sido completada
+ if (xhttp.status === 200 || xhttp.status === 201) {
+ alert("Modificado correctamente");
+ }
+ else {
+ console.log('Error al obtener la petición xhr.status: ' + xhttp.status);
+ }
+ }
+ }
+
+ // Send a request
+ xhttp.open("PUT", "http://localhost:8081/v1/genders/1");
+ xhttp.setRequestHeader("accept","application/json");
+ xhttp.setRequestHeader("Content-Type","application/json");
+ xhttp.send(JSON.stringify({
+ "id": 1,
+ "nombre": "Ciencia Ficción modificado 2"
+ }));
+ }
+
+
+
+