If we want data or logic on our web page, we need to input the data, or we need to code the logic.
Application Programming Interface
{
"name": "Luke Skywalker",
"hasRightHand":false,
"gender": "male",
"vehicles": [
"x-wing",
"snow speeder",
"speeder bike"
],
"lightsabre":{
"color":"green",
"length":"2.5ft",
"yearBuilt":"3 ABY"
}
}this is AJAX
fetch("https://swapi.co/api/people/6")
.then(resp => {
console.log(resp)
});
const request = () => {
fetch("https://swapi.co/api/people/6")
.then(resp => {
if (resp.status === 200){
return resp.json()
} else {
displayErrorMessage(resp)
}
})
.then(json => {
displayData(json)
})
}
but a modern approach is...
const request = async () => {
const resp = await fetch("https://swapi.co/api/people/6")
if (resp.status === 200){
const json = await resp.json()
displayDate(json)
} else {
displayErrorMessage(resp)
}
}