dhtmlxAjax is static object, which means you do not need to instantiate it each time you need to send AJAX request to server. Also, if you use any dhtmlx component on your page, then you do not need to add any script file to use dhtmlxAjax - it is included in all dhtmlx components. Otherwise you need to add dhtmlxcommon.js file.
To send asynchronous GET request and be able to process a response you need to do the following:
dhtmlxAjax.get(url,callbackFunction);
where callbackFunction is a function object which will be called when response from server comes. It gets one argument called loader. This object contains all necessary information about response and some additional capabilities. In details:
To send synchronous GET request you need to do the following:
var loader = dhtmlxAjax.getSync(url);
In case of synchronous request loader object will be returned as a result. It has all features described above.
//async mode dhtmlxAjax.get(url,function(loader){ alert(loader.xmlDoc.responseText); });
//sync mode var loader = dhtmlxAjax.getSync(url); alert(loader.xmlDoc.responseText);
The only difference in making POST request with dhtmlxAjax is additional argument next to URL - POST parameters:
dhtmlxAjax.post(url,params,callbackFunction); var loader = dhtmlxAjax.postSync(url,params);
where params is a string of name=value pairs united with & like
param1=somevalue¶m2=someothervalue