WebMaker provides the option of making asynchronous calls from your pages, either to a Partial Page within WebMaker architecture, or alternatively to a remote Third Party Service. When using these options, FormMaker automatically generates the required JavaScript code to implement the AJAX calls needed for this.
In most cases this default functionality will be fine for your situation, but this can be customised if required to meet your exact circumstances. This is done by creating your own appropriately named JavaScript functions as defined below.
In each method signature, the <identifier> should be the name in FormMaker of the field that initiates the AJAX call. For example, if you had a field defined in FormMaker called 'loadBtn' that was clicked to start the AJAX call you would need to create functions with the following names to make use of this functionality: 'loadBtnConfigureRequestParameters', 'loadBtnSetLoadingMessage', and 'loadBtnManipulateResponse'.
<identifier>ConfigureRequestParameters(requestArgs)
This method is used to configure the request parameters sent to the server. The requestArgs object passed in contains a number of properties that you may want to manipulate. The important ones are as follows:
url : The URL that will be called to access the MVC WebMaker enterprise server platform or remote service.
method : The HTTP method call used - 'post' or 'get'.
postContent : The information that will be posted to the service.
content = <identifier>SetLoadingMessage(message)
This method is used to control the message displayed while the call is being processed. The message parameter will define the current HTML content to be displayed, but this will be overridden by the content returned from this function. This should always return a String containing a valid HTML fragment.
If you do not want to change the state of the display while the call is being made, then return null from this function.
Example: To display an image (e.g. an animated loading icon) before the default message you could do something like the following:
content = <identifier>ManipulateResponse(content, outcome)
This function can be used to manipulate the response returned from the server before it is displayed on the screen. This function must return a String containing a valid HTML fragment, which will be placed directly into the currently rendered page.
The content parameter defines the information retrieved from the service that will currently be rendered, and the outcome parameter provides a boolean value, indicating whether the call was successful or not.
Example: If you wanted to display the current timestamp at the end of the new content, you could define a function like the following:
Please contact Hyfinity if you would like any more details on these available functions.
In most cases this default functionality will be fine for your situation, but this can be customised if required to meet your exact circumstances. This is done by creating your own appropriately named JavaScript functions as defined below.
In each method signature, the <identifier> should be the name in FormMaker of the field that initiates the AJAX call. For example, if you had a field defined in FormMaker called 'loadBtn' that was clicked to start the AJAX call you would need to create functions with the following names to make use of this functionality: 'loadBtnConfigureRequestParameters', 'loadBtnSetLoadingMessage', and 'loadBtnManipulateResponse'.
<identifier>ConfigureRequestParameters(requestArgs)
This method is used to configure the request parameters sent to the server. The requestArgs object passed in contains a number of properties that you may want to manipulate. The important ones are as follows:
url : The URL that will be called to access the MVC WebMaker enterprise server platform or remote service.
method : The HTTP method call used - 'post' or 'get'.
postContent : The information that will be posted to the service.
content = <identifier>SetLoadingMessage(message)
This method is used to control the message displayed while the call is being processed. The message parameter will define the current HTML content to be displayed, but this will be overridden by the content returned from this function. This should always return a String containing a valid HTML fragment.
If you do not want to change the state of the display while the call is being made, then return null from this function.
Example: To display an image (e.g. an animated loading icon) before the default message you could do something like the following:
function loadBtnSetLoadingMessage(message)
{
return '<img src="path/to/image.gif" alt="Loading..."></img>' + message;
}
content = <identifier>ManipulateResponse(content, outcome)
This function can be used to manipulate the response returned from the server before it is displayed on the screen. This function must return a String containing a valid HTML fragment, which will be placed directly into the currently rendered page.
The content parameter defines the information retrieved from the service that will currently be rendered, and the outcome parameter provides a boolean value, indicating whether the call was successful or not.
Example: If you wanted to display the current timestamp at the end of the new content, you could define a function like the following:
function loadBtnManipulateResponse(content, outcome)
{
return content + '<br/>Last Updated: ' + Date();
}
Please contact Hyfinity if you would like any more details on these available functions.
RE: Customising the Generated AJAX Calls
Thank you - this works nicely.
Mike