AJAX Introduction
AJAX Introduction
AJAX Introduction
❮ Previous Next ❯
AJAX Example
Try it Yourself »
https://www.w3schools.com/xml/ajax_intro.asp 1/8
5/16/24, 1:18 PM AJAX Introduction
AJAXTutorials
Example Explained
Exercises Services Sign Up Log in
HTML Page
<!DOCTYPE html>
<html>
<body>
<div id="demo">
<h2>Let AJAX change this text</h2>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
</body>
</html>
The function requests data from a web server and displays it:
Function loadDoc()
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
The "ajax_info.txt" file used in the example above, is a simple text file and looks like this:
https://www.w3schools.com/xml/ajax_intro.asp 2/8
5/16/24, 1:18 PM AJAX Introduction
<h1>AJAX</h1>
Tutorials Exercises Services Sign Up Log in
<p>AJAXJAVASCRIPT
ML CSS is not a programming
SQL language.</p>
PYTHON JAVA PHP HOW TO W3.CSS C C++ C#
<p>AJAX is a technique for accessing web servers from a web page.</p>
<p>AJAX stands for Asynchronous JavaScript And XML.</p>
ADVERTISEMENT
What is AJAX?
AJAX = Asynchronous JavaScript And XML.
A browser built-in XMLHttpRequest object (to request data from a web server)
JavaScript and HTML DOM (to display or use the data)
AJAX is a misleading name. AJAX applications might use XML to transport data, but it is equally
common to transport data as plain text or JSON text.
AJAX allows web pages to be updated asynchronously by exchanging data with a web server
behind the scenes. This means that it is possible to update parts of a web page, without reloading
the whole page.
https://www.w3schools.com/xml/ajax_intro.asp 3/8
5/16/24, 1:18 PM AJAX Introduction
HowTutorials
AJAX Works
Exercises Services Sign Up Log in
❮ Previous Next ❯
W3schools Pathfinder
Track your progress - it's free! Sign Up Log in
ADVERTISEMENT
https://www.w3schools.com/xml/ajax_intro.asp 4/8
5/16/24, 1:18 PM AJAX Introduction
COLOR PICKER
ADVERTISEMENT
https://www.w3schools.com/xml/ajax_intro.asp 5/8
5/16/24, 1:18 PM AJAX Introduction
ADVERTISEMENT
ADVERTISEMENT
https://www.w3schools.com/xml/ajax_intro.asp 6/8
5/16/24, 1:18 PM AJAX Introduction
https://www.w3schools.com/xml/ajax_intro.asp 7/8
5/16/24, 1:18 PM AJAX Introduction
Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.
https://www.w3schools.com/xml/ajax_intro.asp 8/8