AJAX XML
AJAX can be used for interactive communication with an XML file.
The example below shows how a web page can fetch information from an XML file using AJAX technology.
|
|
Course information will be listed here.
|
This example consists of four files:
- a client-side simple HTML form,
- a client-side JavaScript file
ShowCourse.js
,
- a server-side XML file
CourseList.xml
, and
- a server-side PHP file
GetCourse.php
.
The HTML Form
It contains a simple HTML form and a link to a JavaScript file:
<html>
<head><script src="ShowCourse.js"></script></head>
<body>
<form>
<select name="courses" onChange="showCourse( this.value )">
<option value="">Select a course:</option>
<option value="260">CSCI260</option>
<option value="370">CSCI370</option>
...
</select>
</form>
<span id="txtHint">Course information will be listed here.</span>
</body>
</html>
|
It is just a simple HTML form with a simple drop down box called
courses
.
A span called
txtHint
is used as a placeholder for information retrieved from the web server.
When the user selects data, a function called
showCourse
is executed.
The execution of the function is triggered by the
onChange
event.
In other words: Each time the user changes the value in the drop down box, the function
showCourse
is called.