w3schools
  
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About

AJAX Example

« Previous Next Chapter »

To understand how AJAX works, we will create a small AJAX application:

Click to let AJAX change this text


 

Try it yourself »

Your first AJAX application

We will create an AJAX application from scratch. The application will use two click buttons to fetch data from a server and display the information in a web page, without reloading the page itself.

First we create a small HTML page with a short <div> section. The <div> section will be used to display alternative information requested from a server.

To identify the <div> section, we use an id="test" attribute:

<html>
<body>

<div id="test">
<h2>Click to let AJAX change this text</h2>
</div>

<body>
</html>

The we add two simple <buttons>. The buttons will call a function call loadXMLDoc(), when they are clicked:

<button type="button" onclick="loadXMLDoc('test1.txt')">Click Me</button>
<button type="button" onclick="loadXMLDoc('test2.txt')">Click Me</button>

Finally we add a <script> to the page's <head> section to contain the loadXMLDoc() function:

<head>
<script type="text/javascript">
function loadXMLDoc(url)
{
.... Your AJAX script goes here ...
}
</script>
</head>

The next chapters will explain the script (using AJAX), and how to make the application work.


« Previous Next Chapter »


Altova® XMLSpy® - The industry-leading XML editor!

Altova XMLSpy

Whether you're new to XML or already an advanced user, the user-friendly views and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to meet your XML and Web development needs from start to finish. New features in Version 2010!

  • XML editor
  • Graphical XML Schema / DTD editors
  • XSLT 1.0/2.0 editor, debugger, profiler
  • XQuery editor, debugger, profiler
  • XBRL validator, taxonomy editor, taxonomy wizard
  • Support for Office Open XML (OOXML)
  • Graphical WSDL 1.1/2.0 editor & SOAP debugger
  • JSON editing & conversion
  • Java, C#, C++ code generation
  • And much more!

Download a free trial today!

  Altova XMLSpy


WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting
Top Web Hosting
Cheap Web Hosting
WEB BUILDING
Download XML Editor
FREE Flash Website
FREE Web Templates
EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification
STATISTICS
Browser Statistics
Browser OS
Browser Display
FLIGHT TICKETS
Find the cheapest flight
to any destination now!
SHARE THIS PAGE