/*****************************************************************************
*
* Very Simple AJAX engine by U1I
* Version: 0.1
* copyright of this javascript code to U1I. Do not modify.
*
*****************************************************************************/
/*****************************************************************************
*
* HOWTO:
*
* 1. Simple Document Request
*
* loadXMLDoc(url, callback)
* In java script code space or event code space of any element,
* call this function to request and receive a xml document.
*
* url
* The url of a xml document to download into current document.
*
* callback
* When the asyncronous response has arrived, this callback function is
* called back with one argument arrived string data.
*
* [EXAMPLE HTML CODE]
*
*
* Click Here
*
*
* 2. Document Request with Form data
*
* submitFormToXMLDoc(form_id, callback)
* In java script code space or event code space of any element,
* call this function to request and receive a xml document.
*
* form_id
* The id of a form store form-elements containing data to use.
*
* callback
* When the asyncronous response has arrived, this callback function is
* called back with one argument arrived string data.
*
* [HTML CODE]
*
* posttest
*
*
*
*****************************************************************************/
var xmlHTTPReq = null;
var xmlHTTPReqCB = null;
/*
* some work to use XMLHTTPRequest Object
*/
function prepareXmlHTTPRequest()
{
if(window.XMLHttpRequest) {
try {
xmlHTTPReq = new XMLHttpRequest();
} catch(e) {
xmlHTTPReq = false;
}
}
else if(window.ActiveXObject) {
try {
xmlHTTPReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlHTTPReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlHTTPReq = false;
}
}
}
}
function processReqChange()
{
if (xmlHTTPReq.readyState == 4) { // Loaded
if (xmlHTTPReq.status == 200) { // only if "OK"
xmlHTTPReqCB(unescape(xmlHTTPReq.responseText));
} else {
alert("There was a problem retrieving the XML data:\n" + xmlHTTPReq.statusText);
}
}
}
/*
* Simple Call for requesting Document
*/
function loadXMLDoc(url, cb)
{
prepareXmlHTTPRequest();
if (xmlHTTPReq) {
xmlHTTPReqCB = cb;
xmlHTTPReq.onreadystatechange = processReqChange;
try {
xmlHTTPReq.open("GET", url, true);
xmlHTTPReq.send("");
} catch (e) {
alert("There may be one or more problem to execute XML request");
}
}
delete xmlHTTPReq;
}
/*
* call of Form element for requesting Document
*/
function submitFormToXMLDoc(form_id, cb)
{
var form;
var method;
var action;
var postData = "";
form = document.getElementById(form_id);
if ( !form ) {
alert("check form id");
return false;
}
method = form.method.toUpperCase();
if ( !method ) {
alert("form must have an attribute 'method'");
return false;
}
action = form.action;
if ( !action ) {
alert("form must have an attribute 'action'");
return false;
}
prepareXmlHTTPRequest();
if (xmlHTTPReq) {
xmlHTTPReqCB = cb;
xmlHTTPReq.onreadystatechange = processReqChange;
}
else {
return false;
}
if (method == "POST") {
xmlHTTPReq.open(method, action, true);
if (xmlHTTPReq) {
for (i=0; i