The Ajax and Request Objects
Ajax and request objects allow you to send requests to the server and process response sent back from the server. Requests contain XML data that you want to process on the server. Responses depend completly on your application.
Example
var ddlLanguages = new TDropdownList();
var layHorizontal = new THorizontalLayout();
var wndAjaxRequestSample = createWindow('Ajax Request Sample');
var onLanguagesError = function(text) {
TMessageBox.showModal('Error', 'Could not get languages!');
};
var onLanguagesOk = function(xmlDoc, text) {
ddlLanguages.clear();
var elements = xmlDoc.getElementsByTagName('Language');
for (var i = 0; i < elements.length; i++) {
var nodes = elements[i].childNodes;
if (nodes.length == 2) {
if (nodes.item(0).firstChild != null && nodes.item(0).firstChild.nodeValue != null && nodes.item(1).firstChild != null && nodes.item(1).firstChild.nodeValue != null) {
ddlLanguages.add(nodes.item(0).firstChild.nodeValue, nodes.item(1).firstChild.nodeValue);
}
}
}
ddlLanguages.setSelectedFirst();
wndAjaxRequestSample.refresh();
};
var request = new TRequest();
TAjax.sendRequest(wndAjaxRequestSample, 'GetLanguageList.php', request.getRequest(), onLanguagesOk, onLanguagesError);
layHorizontal.add(new TText('Languages:'));
layHorizontal.add(ddlLanguages);
wndAjaxRequestSample.add(layHorizontal);
showModal(wndAjaxRequestSample);

In the previous example, we sent a request to the server to fetch languages names and added them to the Dropdown List object.
Ajax Object
Ajax object is a shared object that you can use to send asynchronous requests to the server:
TAjax.sendRequest(parentObject, serverScript, data, okCallback, errorCallback, contentType);
Where:
-
parentObject is the object who sends the request (in most of the time it will be window object).
-
serverScript is the script that will handle the request on the server side.
-
data is the XML data that you will send in the request via request object.
-
okCallback is a callback that will be called when the request is finished and the response is ready and the state of the request is OK.
-
errorCallback is a callback that will be called when the request is finished and the response is ready but the state of the request is not OK.
-
contentType is the request content type. By default, the content type is 'text/xml; charset=UTF-8'.
Request Object
Request object will structure and hold request data as XML. Use add method to add data to the request object. Form:
add(propertyName, propertyValue, encode)
Where:
-
propertyName is the XML tag name.
-
propertyValue is the XML tag value.
-
encode when true the tag value is HTML decoded. Default value is true.
var request = new TRequest();
request.add(name, value); // <name>value</name>
Use getRequest property to get data held in the request object: request.getRequest();.