Asynchronous Responses and Callbacks

Within the generated framework, all responses to Web service calls are received asynchronously. Consequently, you must provide the equivalent of an event handler, called a callback function, to handling a response.

The following example shows the definition and registration of a callback function.

function handleResponse (xml) {
    alert("The Web service replied");
}
Jade.CustomerService.getAge("John", "Smith", {callback: handleResponse});

The framework enables you to pass a config object as an additional parameter to each Web service call. You can set properties on the config object to specify how the framework deals with the call.

In the previous example, the callback property is set to refer to a function that will be invoked when the Web service replies. The function is passed the XML returned by the Web service. You could then extract the parts of the reply in which you are interested (for example, by using a helper library such as jQuery) and carry out processing based on the response.