Python AJAX & XMLHttpRequest (responseXML)
AJAX (Asynchronous JavaScript and XML) allows web applications to load data from servers in the background without refreshing the web page. The XMLHttpRequest object provides a built-in responseXML property that automatically parses fetched XML into a DOM Document.
"AJAX is like an office assistant who walks over to the archive room in the background, grabs an XML file, and hands it to you at your desk without interrupting your current phone conversation."
Deep Dive: How It Works
XMLHttpRequest (XHR): Browser networking API that historically established the acronym AJAX.
xhr.responseXML: Automatically returns a parsed XML DOM Document when the response header is text/xml or application/xml.
xhr.onreadystatechange: Event handler tracking readyState 4 (DONE) and status 200 (OK).
Syntax Blueprint
xhr.open("GET", "data.xml", true);
xhr.onload = () => { const doc = xhr.responseXML; };Fetches XML over HTTP and accesses the pre-parsed DOM tree via xhr.responseXML.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
responseXML is null when fetching an XML file.Why it happens: If the server does not send Content-Type: text/xml or application/xml, the browser will not populate responseXML.
How to fix: Call xhr.overrideMimeType("text/xml") or parse xhr.responseText with DOMParser.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Extract API response code from XML
Given `const payload = "<api><code>AUTH_OK</code></api>";`
Parse with DOMParser and print "Response Code: AUTH_OK".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.