Avoiding mixing client-side and server-side APIs
When working with client-side and server-side APIs, you must clearly understand
the difference between the two API definitions to avoid using client-side APIs for
server-side APIs, or vice-versa. All server-side APIs are prefixed with rbv_api.
and all client-side APIs are prefixed with rbf_
. Unlike client-side APIs, server-side APIs cannot be
executed in the Web browser directly. If you must execute a server-side API in a
client-side script, you must enclose the server-side API in an #EVAL[ ]
block. The following section describes, with examples, how to
avoid mixing client-side and server-side APIs.
The following script, when added to a page's script component, will cause a
runtime error because an rbv_api.
variable (a
server-side API) is not recognized by a Web browser’s script:
<h2>Number of Clients: <span id='counter'></span></h2> <script> var count = rbv_api.selectNumber("select count(1) from client"); document.getElementById("counter").innerHTML = count; </script>
The two ways to fix the above error are:
- Enclose the server-side API in an
#EVAL[ ]
block:<h2>Number of Clients: <span id='counter'></span></h2> <script> var count = #EVAL[ rbv_api.selectNumber("select count(1) from client"); ]; document.getElementById("counter").innerHTML = count; </script>
Note: When working with Script components, you can use the Test EVAL[] Block button to debug/develop server-side script. - Use a client-side API instead of a server-side
API:
<h2>Number of A: <span id='counter'></span></h2> <script> rbf_selectNumber("select count(1) from a", function(value) { document.getElementById("counter").innerHTML = value; }); </script>
Typically, server-side API execution is faster and it is not subjected to a limit on the number of AJAX calls allowed per login session. A client-side API is used whenever user input can only be made available during runtime and not when the Web browser page is rendered.