AJAX Introduction (2024)

AJAX is a developer's dream, because you can:

  • Update a web page without reloading the page
  • Request data from a server - after the page has loaded
  • Receive data from a server - after the page has loaded
  • Send data to a server - in the background

Try it Yourself Examples in Every Chapter

In every chapter, you can edit the examples online, and click on a button to view the result.

AJAX Example Explained

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 HTML page contains a <div> section and a <button>.

The <div> section is used to display information from a server.

The <button> calls a function (if it is clicked).

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:

<h1>AJAX</h1>
<p>AJAX is not a programming language.</p>
<p>AJAX is a technique for accessing web servers from a web page.</p>
<p>AJAX stands for Asynchronous JavaScript And XML.</p>

What is AJAX?

AJAX = Asynchronous JavaScript AndXML.

AJAX is not a programming language.

AJAX just uses a combination of:

  • 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.

How AJAX Works

AJAX Introduction (1)

  • 1. An event occurs in a web page (the page is loaded, a button is clicked)
  • 2. An XMLHttpRequest object is created by JavaScript
  • 3. The XMLHttpRequest object sends a request to a web server
  • 4. The server processes the request
  • 5. The server sends a response back to the web page
  • 6. The response is read by JavaScript
  • 7. Proper action (like page update) is performed by JavaScript

AJAX Introduction (2024)
Top Articles
Highest Paying Jobs in China | Leverage Edu
Houston Wrongful Death Lawyer
Evil Dead Rise Review - IGN
W B Crumel Funeral Home Obituaries
Honda Odyssey Questions - P0303 3 cyclinder misfire
7 Best Character Builds In Nioh 2
Teacup Yorkie For Sale Up To $400 In South Carolina
Farmers And Merchants Bank Broadway Va
Walmart Tire Service Hours
New & Used Motorcycles for Sale | NL Classifieds
Blind Guardian - The God Machine Review • metal.de
1888 Metro 8
Seattle Rub Rating
Northwell.myexperience
How to find cash from balance sheet?
Atl To London Google Flights
Huniepop Jessie Questions And Answers
Overload RS3 Guide - Rune Fanatics
FREE Printable Pets Animal Playdough Mats
Troy Bilt Belt Diagram
Verity Or Falsity Of A Proposition Crossword Clue
Ip Address Issue Nad 3303
Meridamoonbeams
Drys Pharmacy
BCLC Launches PROLINE Sportsbook at B.C. Retail Locations
Thermal Pants Mens Walmart
New Orleans Magazine | Dining, Entertainment, Homes, Lifestyle and all things NOLA
Is Jackson On Jeopardy Transgender
Belly Button Torture Video
20 of the Best Restaurants in Moscow, Russia by a Local
Boone County Sheriff 700 Report
Craigslist Chester Sc
Prisoners Metacritic
Reisen in der Business Class | Air Europa Deutschland
Anmed My Chart Login
Zip Tv Guide
One Person Dead In East Charlotte - WCCB Charlotte's CW
Best Hair Salon Dublin | Hairdressers Dublin | Boombae
Etfh Hatchery
Black Myth Wukong All Secrets in Chapter 6
Curaleaf Announces Majority Stake and Forms Strategic Partnership with Germany's Four 20 Pharma, a Fully EU-GMP & GDP Licensed Producer and Distributor of Medical Cannabis
Smokingmeatforum
Craigslist Creative Gigs
EnP. Karl Sam Maquiling on LinkedIn: #anniversary #localgovernment #urbanplanning #goodgovernance…
Sour Power OG (Karma Genetics) :: Cannabis Strain Info
Brokaw 24 Hour Fitness
Ultimate Guide to Los Alamos, CA: A Small Town Big On Flavor
Swoop Amazon S3
Finastra Gfx
Fraction Button On Ti-84 Plus Ce
Having A Short Temper Nyt Crossword Clue
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 6014

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.