Chapter 21: XML AJAX

XML + AJAX — written as if I’m sitting next to you, explaining everything step by step like a patient teacher.

We will go slowly and clearly:

  • What AJAX really is
  • Why it was historically connected with XML
  • Why the name is misleading today
  • How AJAX works in practice (with and without XML)
  • Realistic, modern examples you can actually try
  • Common patterns people still use in 2025–2026

Let’s begin.

1. What is AJAX? (The clearest explanation)

AJAX = Asynchronous JavaScript and XML

It is not a programming language or a new technology.

It is a technique / pattern that allows web pages to:

  • Send data to a server
  • Receive data from a server
  • Update parts of the page without reloading the entire page

The name “AJAX” was invented around 2005 when people started doing this heavily, and at that time XML was the most common data format being exchanged.

Important truth in 2025–2026:

Today almost nobody uses XML with AJAX anymore. The name AJAX stuck, but in reality most AJAX calls use JSON.

Still — understanding the original XML-based AJAX is important because:

  • You will see it in very old codebases
  • Many tutorials/books still teach it this way
  • Some legacy enterprise systems (banks, government portals, ERP integrations) still return XML

2. Classic AJAX with XML – How it looked ~2005–2015

Typical flow:

  1. JavaScript creates an XMLHttpRequest object
  2. Sends a request to the server (GET or POST)
  3. Server returns data as XML
  4. JavaScript parses the XML and updates the page

Very classic example (XMLHttpRequest + XML response)

HTML page

HTML

Server-side PHP file (get-student.php) — returns XML

PHP

What happens when you click the button:

  1. Browser sends GET request → get-student.php?id=101
  2. Server returns XML
  3. JavaScript receives it as responseXML (parsed DOM)
  4. Extracts values using DOM methods (getElementsByTagName)
  5. Updates only the <div id=”result”> — no page reload

This is classic AJAX with XML — exactly how Google Maps, early Gmail, and many web 2.0 apps worked around 2005–2010.

3. Modern AJAX – JSON is King (what you see in 2025–2026)

The same example today — almost nobody returns XML anymore

Server returns JSON instead

PHP

Modern JavaScript (using fetch – preferred today)

JavaScript

Key differences:

  • fetch instead of XMLHttpRequest (cleaner, Promise-based)
  • response.json() instead of responseXML
  • Much simpler parsing — no need to walk DOM tree
  • Smaller payload (JSON is usually more compact than XML)

4. When You Still See XML + AJAX in Real Projects (2025–2026)

Situation Typical pattern Why XML?
SOAP web services AJAX → SOAP XML request/response Standard requires XML + SOAP envelope
Legacy enterprise APIs XMLHttpRequest or fetch to old endpoint Old system only speaks XML
Some government / banking portals POST XML to specific endpoint Regulatory requirement (e.g. GST e-invoice)
Very old admin panels / CMS AJAX calls returning XML fragments Never migrated
Report generation Fetch XML → transform with XSLT in browser Rare, but exists in publishing systems

5. Quick Summary – XML + AJAX in One Page

Period Dominant data format Main JavaScript method Typical payload size Still common in 2025–2026?
2005–2012 XML XMLHttpRequest Larger Legacy code only
2013–2020 JSON (transition) XMLHttpRequest / jQuery Smaller Still seen
2020–2026 JSON fetch + async/await Smallest Dominant
Enterprise / legacy XML XMLHttpRequest or fetch Larger Very common in some domains

Practical advice:

  • Learn how to read XML (even if you never produce it)
  • Know how to use responseXML and basic DOM parsing
  • But prefer JSON + fetch for anything new
  • Be ready to deal with XML when working with banks, governments, insurance, ERP systems, SOAP services

Would you like to go deeper into any of these directions?

  • Full SOAP client example using AJAX
  • How to parse complex XML responses in JavaScript
  • Modern fetch + XML pattern (when you have no choice)
  • Converting old XML AJAX code to JSON
  • Using XSLT in browser with AJAX-fetched XML (rare but interesting)

Tell me what interests you most right now! 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *