// the XMLHttpRequest object I created in the constructor is called this.httpReqObj
// this.queryAddr is the servlet that handels the responses
if(this.httpReqObj == null || this.queryAddr == null)
{
return(false);
}
// check if XMLHttpRequest object is ready to send a new request.
if(this.getReadyState() != 0 && this.getReadyState() != 4)
{
return(false);
}
// the message queue contains strings, that should be sent to the server
if(this.msgQueue.hasNext())
{
var bundleMsg = "";
var bundleCtr = 0;
while(this.msgQueue.hasNext() && bundleCtr < DataRequester.BUNDLE_FACTOR)
{
bundleCtr ++;
bundleMsg += this.msgQueue.consume() + "&";
}
// remove last character of string
bundleMsg = bundleMsg.substring(0, bundleMsg.length - 1);
// "POST": choose the transport mechanism to the server
// "this.queryAddr": URL to which the query should be sent
// "true": communication should be asynchron
// if argument not available, assume method is true
if(typeof method == 'undefined')
{
method = true;
}
this.httpReqObj.open("POST", this.queryAddr, method);
// this function is called every time the status
// of the http request has changed. There exist five states.
// 0: not initialized
// 1: currently loading
// 2: finished loading
// 3: waiting for return
// 4: finished
if(method)
{
this.httpReqObj.onreadystatechange = createObjectCallback(obj, func);
}
// create header for POST query
this.httpReqObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.httpReqObj.setRequestHeader("Content-length", bundleMsg.length);
// send data to server
this.httpReqObj.send(bundleMsg);
// synchronous request
if(method == false)
{
return(this.getResponseXML());
}
}else
{
return;
}