The code. Here are two JavaScript files for the taking
You are free to take the code and modify it or use it as is in any kind of project. This is code is intended for demonstration and you are responsible for its reliability and fitness for purpose in your projects.
You can check the following resources on this topic and see different permutations on how to do remote scripting with an XMLHttprequest object (AJAX). Seeing other's explanations can help you adapt this script to your project needs.
Jibbering: Using the XML HTTP Request object
Apple Developer Connection: Dynamic HTML and XML: The XMLHttpRequest Object.
O'Reilly Onlamp.com: A Simpler Ajax Path.
Mozilla Developer Center: Asynchronous JavaScript and XML (AJAX)
Quirksmode: 2005: The year of data retrieval.
Sitepoint: AJAX: Usable Interactivity with Remote Scripting
XML.com: Very Dynamic Web Interfaces
fiftyfourelven: Index to serveral articles
Lukw Interface Designs: AJAX & Interface Design