Main projects
- Rialto NEW !!
- Rialto GWT NEW !!
This component will allow exchange of data with the server. It is based on the XMLHttpRequest object. This tutorial will show you an exemple to use the ajaxRequest component. We will get customer information just after selecting his name.
the init parameters are:
The init call look like this:
exemple:
var ajaxReq=new rialto.io.AjaxRequest({
url:"/getCustomer?NAME=SMITH",
method: 'get',
withWaitWindow:true,
onSuccess: refreshData,
onFailure: failureCall
})
To request on the server just call the load method as:
exemple:
ajaxReq.load("NAME=SMITH");
The parameter of this function is the querry string. With the 'get' method, the parameters can be add to the url and the load function is call with an empty string
exemple:
var ajaxReq=new rialto.io.AjaxRequest({
url:"/getCustomer?NAME=SMITH",
method: 'get',
withWaitWindow:true,
onSuccess:refreshData,
onFailure:failureCall
})
ajaxReq.load("");
The callback function use the request object as parameter
If you retrieve javascript data use the javascrit eval function in the callback method with the responseText propertie of the request
exemple:
if the server send back something like
{name:“SMITH”, firstName:“BOB”, age:“23” };
function refreshData(request){
eval("var resp="+request.responseText);
var name=resp.name;
var firstName=resp.firstName;
var age=resp.age;
}
If you retrieve XML data use in the callback method the responseXML propertie of the request
exemple:
if the server send back something like
<response> <customer name="SMITH" firstName="BOB" age="23"/> </response>
then the ajax callback method can look at this:
function refreshData(request){
var xmlDoc = request.responseXML;
var rootNode =xmlDoc.getElementsByTagName("response")[0];
var childNode= rootNode.getElementsByTagName("customer")[0];
var name=childNode.getAttribute("name");
var firstName=childNode.getAttribute("firstName");
var age=childNode.getAttribute("age");
}