Roles of Browser, Server, and Database in AJAX
When you use AJAX to fetch or send data, three main components work together:
1. Browser (Client-Side)
Example:
2. Server (Backend)
Example:
-
The server receives the city name from the browser.
-
It requests weather data from the database or an external API.
-
It sends the processed weather information back to the browser.
3. Database (Data Storage)
-
The database stores, retrieves, and manages the data requested by the server.
-
Common databases: MySQL, PostgreSQL, MongoDB, Oracle, Firebase, etc.
-
It:
-
Executes queries sent by the server.
-
Returns data quickly and efficiently.
-
Doesn’t communicate directly with the browser — only through the server.
Example:
-
The database stores weather data for multiple cities.
-
When the server asks for London’s weather, the database sends back the temperature, humidity, and conditions.
How It Works — Step by Step
Let’s take an example of a weather app:
Scenario:
You enter "London" in a weather search bar.
Step 1: User Action (Browser)
Step 2: AJAX Request
Step 3: Server Processing
Step 4: Database Response
Step 5: Server Response
-
The server formats the data into JSON:
{
"city": "London",
"temperature": "22°C",
"condition": "Sunny"
}
-
It sends this JSON response to the browser.
Step 6: Browser Updates Page
Diagram: AJAX Workflow
User (Browser) → (AJAX Request) → Server → (Query) → Database
Database → (Data) → Server → (JSON Response) → Browser (Update Page)