Web Programming

AJAX & Promise & Fetch API

Attention is All You Need 2021. 5. 6. 12:46

- AJAX stands for Asynchronous JavaScript and XML.

- AJAX is not a technology in itself, but the use of XMLHttpRequest to communicate with servers.

 

Asynchronous Web Applications

- Using AJAX, we can update web pages asynchronously, meaning updating parts of a page without reloading the whole page.

- This concept allows apps to be faster and more responsive to user actions.

- By creating a XMLHttpRequest object which manages a request, it sends a request to the server, awaits for the response, and invokes a callback function.

 

Synchronous Web Applications

- In contrast, Synchronous means loading the new page and temporarily making the browser window blank, so that the client has to wait for the server to respond.

 

 

 

Example of Asynchronous request

- We first create an XMLHttpRequest object, which will tell the request object which function will handle the response using the traditional method.

 

methods for making request to server

- Using the open() and send() method, we can actually make a request to the server.

- If we decided to use the POST method instead of GET method, we can send any data to the server using the send() method.

 

Properties of XMLHttpRequest object

- After checking the request's state at the callback function and the HTTP response status, we get to do whatever we want with the data the server sent.

- Using JSON.parse(), we change the response into a object.

 

 

- XML and jQuery are outdataed technologies that do similar roles.