Asynchronous JavaScript
Working with AJAX (asynchronous JavaScript and XML) and the fetch API- used to make http requests to files, APIs and services (your own or external REST API)
Fetch is a newer standard.
Block and code- block until posts are fetched.
Asynchronous – pulls posts out of a synchronous function, but posts a call back, the do the next thing function does not have to wait- program will keep going.
Faster.
Most Async code will
be part of an API or library:
· XMLHttpRequest and Fetch API
· External libraries: jQuery Ajax (bloated), Axios, or other HTTP libraries (Superagent)
· Node.js fs (filesystem)module, Node http
How to handle Async
code:
· Callbacks
· Promises
· Async/Await
AJAX isn’t a language
or a framework; it is a set of web technologies
· Sends and receive data from the client and server
· Done behind the scenes
· Don’t have to reload the web page
· XML has been replaced by JSON
· AJAX can alos work with plain text
· Fetches data
· Very interactive
· Can update little section of text without reloading web page
· AJAX call goes through an AJAX engine
· Uses XMLHttpRequest
· Parse and use data in application
· JS Call goes out from browser
· AJAX engine sends HTML response
· API has to have permissions granted
· COREs are enabled, and cross domain requests and made
· OAuth – used for authentication
· API in the form of an object
· Provided by the browsers javascript environment
· Methods transfer data between client and server
· Can be used with other protocols than http
· Can work with data other than XML (JSON, plain text)
· Fetch is part of Vanilla JS is what is recommended