Hindi Songs

Search About PHP!!!

Thursday, July 9, 2009

AJAX XML example

The following example will demonstrate how a web page can fetch information from an XML file with AJAX technology.

Select a CD:

CD info will be listed here...


Example explained - The HTML page

The HTML page contains a link to an external JavaScript, an HTML form, and a div element:

<>
<>
< type="text/javascript" src="selectcd.js">< /script >
< /head >

<>

<>
Select a CD:
< name="cds" onchange="showCD(this.value)">
< value="Bob Dylan">Bob Dylan< /option >
< value="Bonnie Tyler">Bonnie Tyler< /option >
< value="Dolly Parton">Dolly Parton< /option >
< /select >
< /form >

< id="txtHint">
CD info will be listed here...< /b >< /div >

< /body >
< /html >

As you can see it is just a simple HTML form with a simple drop down box called "cds".

The <> below the form will be used as a placeholder for info retrieved from the web server.

When the user selects data, a function called "showCD" is executed. The execution of the function is triggered by the "onchange" event. In other words: Each time the user change the value in the drop down box, the function showCD is called.