Ajax (also spelled AJAX) stands for Asynchronous JavaScript and XML. These days, however, you're more likely to work with JSON than XML, so the name is a bit misleading. On to code: take a look at https://github.com/PacktPublishing/Hands-on-JavaScript-for-Python-Developers/blob/master/chapter-4/ajax/swapi.html. Open this locally, and in your developer tools, you should see a JSON object as follows:
Figure 4.7 – SWAPI Ajax result
Congratulations! You've made your first Ajax call! Let's break down the following code:
fetch('https://swapi.co/api/people/1/')
.then((response) => {
return response.json()
})
.then((json) => {
console.log(json)
})
fetch is a fairly new API in ES6 that essentially replaces the older, more complicated way of making Ajax calls with XMLHttpRequest. As you can see, the syntax is fairly concise. What might not be obvious is the role that the .then() functions play—or even...