`
kaksha.dev
HTTP(Hypertext Transfer Protocol) and AJAX(Asynchronous JavaScript and XML) together refers to web developent technique of using AJAX to make HTTP requests from a web page without reloading the entire page.
HTTP is an application-layer protocol used for communication between a client (such as a web browser, mobile app etc.) and a server over a network.
An HTTP request message typically contains:
An HTTP response generally contains:
HTTP headers provide the information about the request. They are key-value pairs and has meta data about the request e.g., Content-Type, Authorization, Request Method, Content-Length, User-Agent etc.
AJAX is a technique that allows JavaScript running in the browser to asynchronously communicate with server and update the full or parts of a webpage wihout a complete reload.
Before AJAX, this is how browser used to communicate with server and update the webpages. When an user performs any client side action (form submit / button click), the server responds with entire new HTML page.

With AJAX, when a user performs an action on a web page, JavaScript sends an HTTP request to the server. The server returns data (typically in JSON format), which JavaScript then uses to update only the relevant part of the web page.

Despite its name, AJAX is now mostly used with JSON rather than XML. This is because, when AJAX was introduced, XML was the most common data exchange format. Today, however, JSON is the preferred format for data exchange.
<user>
<id>1</id>
<name>John Doe</name>
<age>25</age>
</user>
{
"id": 1,
"name": "John",
"age": 25
}
There are two primary ways to make AJAX requests over HTTP: