In the early web, every action that needed new data reloaded the whole page. AJAX removed that limit by letting a page talk to the server in the background.
What AJAX Is
AJAX stands for Asynchronous JavaScript and XML. It is a technique and not a language. A script sends a request to a server, the page keeps working, and when the answer arrives the script updates only the part of the page that needs it. Today the data is usually JSON rather than XML, but the name has stayed.
Definition: AJAX. A technique for sending and receiving data from a server in the background, without reloading the page.
Synchronous and Asynchronous Requests
In a synchronous request, the page stops and waits until the reply arrives. In an asynchronous request, the page stays usable. A function runs later, when the data arrives, to handle the reply. Because the wait for a server can take seconds, asynchronous requests are the normal choice.
Definition: Asynchronous request. A request that lets the page keep working while it waits for the reply.
Table 4.5: Synchronous and asynchronous requests
| Aspect | Synchronous | Asynchronous |
|---|---|---|
| During the wait | Page is frozen | Page stays usable |
| Reply handled | Right after the call | Later, by a handler |
| Use today | Almost never | The normal way |
Advantages
Only the needed data travels, so less bandwidth is used and pages feel faster. Parts of a page, such as a search suggestion list or a message count, update by themselves. The user's place on the page, and the text typed in other fields, is not lost by a reload.
Disadvantages
The browser's back button and bookmarks may not match what is on screen, because the address does not change. Search engines may not see content that arrives only after a script runs. The page depends on JavaScript being enabled, and errors in the background are easy to miss unless the code reports them.
Example 4.5: A live search
A user types the letters "as" in a search box on a college site.
- A script sends the text to the server without reloading the page.
- The server finds the names that begin with "as" and returns them.
- The script receives the list and fills a drop-down below the box.
- The user keeps typing, and the list updates each time.
The rest of the page, including text in other boxes, stays exactly as it was.
Common mistakes
- Calling AJAX a programming language, when it is a technique that uses JavaScript.
- Using synchronous requests, which freeze the page.
- Forgetting that AJAX content may be missing for search engines.
- Not handling errors, so that a failed request leaves the user with no message.
Key takeaways
- AJAX fetches data in the background, so the page does not reload.
- Asynchronous requests keep the page usable while the reply is awaited.
- Advantages are speed and less data, and disadvantages are back button, search engines and script dependence.
- A handler runs when the reply arrives.
Practice questions
- What does the A in AJAX stand for?
- Give one advantage and one disadvantage of AJAX.
- What is the difference between synchronous and asynchronous requests?
Answers to the practice questions
- Asynchronous.
- Advantage: only part of the page updates, so it is faster. Disadvantage: the back button and bookmarks may not match the screen.
- A synchronous request freezes the page until the reply arrives, while an asynchronous one lets the page keep working.
Sources
- Official BCA syllabus (NEP 2025 scheme), Web Application Development, course code 25BCA405DS04, Unit IV
