WebAsyncPreparePoll Function

Action

Prepares an asynchronous communication channel for the poll model. The next BDL API call must be a low-level web API call, which will initiate an asynchronous communication channel. Asynchronous page-level API calls are not supported. The asynchronous request(s) happen in the background and will be executed in parallel to subsequent BDL API calls in the script.

An asynchronous communication channel is closed either by calling the BDL function WebAsyncStop() or when the browser session ends or at the end of the transaction if first time user behaviour is configured.

The poll requests will be performed automatically at the specified interval until the asynchronous communication channel is closed. The callback will be called exactly once for each poll request.

Include file

webapi.bdh

Syntax

WebAsyncPreparePoll( in fInterval          : double,
                     in cbResponseCallback : callback optional ): number;
Parameter Description
fInterval The interval of the poll requests in seconds. If a poll request takes longer than the interval time, the following request will be performed immediately afterwards.
cbResponseCallback The asynchronous response callback function. It has to be passed with the callback keyword (for example: callback(FCallback). The function has to be declared as follows:

function FWebAsyncResponseCallback(sResponseBody : string) <ASYNC_CALLBACK_FUNCTION>.

The function has to be of type ASYNC_CALLBACK_FUNCTION. sResponseBody of the callback contains the content of the current response message part.

Return value

  • true if successful

  • false otherwise

Example

dclfunc
  function FAsyncCallback(sResponseBody : string) <ASYNC_CALLBACK_FUNCTION>
  var
  begin
     RepMessage("RESPONSE: " + sResponseBody, SEVERITY_INFORMATIONAL);
  end FAsyncCallback;

dcltrans
  transaction TMain
  var
    nAsyncChannel : number;
  begin
    WebPageUrl("http://ajaxify.com/run/wiki/", "Ajax Wiki Demo");
 
    nAsyncChannel := WebAsyncPreparePoll(5.0, callback(FAsyncCallback));
    WebFormGet("http://ajaxify.com/run/wiki/content.php", WIKI_MESSAGES);
 
    Wait(23.0);
    
    WebAsyncStop(nAsyncChannel); // can be ommitted at the end of the transaction/script
    
  end TMain;