AJAX Database
AJAX can be used for interactive communication with a database.
The following example will demonstrate how a web page can fetch information from a database with AJAX:
Book information will be listed here...
The MySQL Database
The database table creation and population are given as follows:
create table bookList (
ISBN char(16) primary key,
title varchar(64) not null,
authors varchar(64),
price real,
quantity integer );
insert into bookList values (
0596005601, 'Learning PHP 5', 'David Sklar', 19.77, 32 );
insert into bookList values (
0596003064, 'High Performance MySQL', 'Jeremy D. Zawodny', 26.37, 221 );
...
|
The HTML Form
This AJAX contains an HTML form and a link to a JavaScript file.
When a user selects a book in the dropdown list above, a function called
showBook
is executed.
The function is triggered by the
onChange
event:
<html>
<head><script src="ShowBook.js"></script></head>
<body><form action="">
<select name="books" onChange="showBook(this.value)">
<option value="">Select a book:</option>
<option value="0596528388">AJAX</option>
<option value="1118008189">HTML</option>
...
</select></form>
<div id="txtHint">Book information will be listed here...</div>
</body>
</html>
|