-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclase30.js
More file actions
30 lines (22 loc) · 1.04 KB
/
clase30.js
File metadata and controls
30 lines (22 loc) · 1.04 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
const API_URL = 'https://swapi.co/api/'
const PEOPLE_URL = 'people/:id'
//const LUKE_URL = `${API_URL}${PEOPLE_URL.replace(':id', 1)}`
const opts = { crossDomain: true }
const onPeopleResponse = function (character) {console.log(`Hola yo soy, ${character.name}`);
//console.log(arguments)
//imprime los parametros que recibe la funcion
}
function obtenerPersonaje(id) {
const URL = `${API_URL}${PEOPLE_URL.replace(':id', id)}`
$.get(URL, opts, onPeopleResponse)
}
obtenerPersonaje(1)
obtenerPersonaje(2)
obtenerPersonaje(3)
obtenerPersonaje(4)
//Asincronismo en su maximo esplendor, no sabemos en que orden nos van a llegar
//las respuesta, depende del servidor y de cuanto tarda en responder cada uno de los request
//$.get() nos permite hacer un request y es un metodo que pertence a jquery
//Callback es una funcion que se va ejecutar en algun futuro y no sabemos cuando
//Un callback es una función que se pasa a otra función como un argumento.
//Esta función se invoca, después, dentro de la función externa para completar alguna acción.