Introduction to the HTML DB Ajax Framework.

To help build our AJAX enabled functionality we created an AJAX framework that allows us to quickly access HTML DB items and application processes. This is not a complete list of properties and methods available to the the object but the ones that are most useful and generally used, also I am not documenting functionality that I know will be changing in future versions.

What can I do with HTML DB and AJAX?

In it's most simple usage using AJAX you can update a portion of an HTML DB page without reloading the whole page. While that seems rather minor it can provide huge improvments in page loading time and user experience.
Examples
  • Update a form items based on changes to another form item. example
  • Loading extended information on a report row but only if requested. example
  • Create a Tree Item where only branchs that are requested are loaded. example
  • Pull content from another page. example
  • Pull content from an application process. example

Creating the htmldb_Get Object

The htmldb_Get() javascript file is included into every HTML DB page by default so to start working with it you don't need to change any

htmldb_Get() has seven parameters that can be set on initialization lets go over them one at a time, I will give the parameters name the type of variable it expects a brief description of what it is and then a list of hints for usage.



var g_GetSomething = htmldb_Get(obj,flow,req,page,instance,proc,queryString);



Parameters

obj : (HTML DOM element or a string id or null)  element that the return text will be inserted into
    1. if you don't want to immediately insert the return into the page provide null the get method can still be used to return a string/XML into a variable.
    2. if obj is set to an input or textarea it will set the objects value attribute other HTML elements have the innerHTML attribute set.
    3. if you are returning an XML snippet provide a null

flow : (string) the HTML DB flow id for the xmlhttp post
    1. Almost always the best option is to put html_GetElement('pFlowId').value as this parameters value [this will be the default in next version].

req : (string or null) the HTML DB request value for the xmlhttp post also to call an ondemand process
    1. If you are calling an ondemand process the format would be APPLICATION_PROCESS=mytestprocess where you replace mytestprocess with your process name.
    2. This is the standard HTML DB request object so it's very useful for conditional rendering if you are pulling content from a page.
page : (string) the HTML DB page id for the xmlhttp post
    1. If you are accessing an ondemand process this can be set to any page but if you are using authentication in your application the user either needs to be authenticated or it needs to be a public page. [page 0 will be the default in next version]
    2. If you are accessing page content set this to the page id that you will be pulling content from.
instance : (string) the HTML DB session id (leave null)
    1. leave as null and the object will get the session id from the page there is  almost no reason to ever change this and it will probably be removed in a future version
proc : (string) use this if you are calling a procedure with URL syntax
    1. This is usually not used.

queryString : (string)
Adds extra query strings to the end of your post URL
    1. This is usually not used.

Using the the htmldb_Get() Item


Methods


.add(name,val) the add method is how you set item variables in the session
  • name : (string) is the the name of the item you want to set as a string
  • val : (string) is the value to set the item too
    1. you can set the value of any HTML DB item, items on the current page, application level items, items on other pages.
    2. you can set multiple items by applying multiple .add() calls to the AJAX object.
    3. if the value you need to add is transient look into using application level items such as TEMPORARY_ITEM as this will make your code more generic


.get(mode,startTag,endTag) the get method submits the Ajax object to the HTML DB engine
  • mode : (string) return mode it can be null , XML
  • startTag : (string) begin clipping at this string
  • endTag : (string) end clipping at this string
    1. if mode is set to null the return will be a javascript string object so you can store in a javascript variable.
    2. if mode is set to XML the return value is a javascript XML object [you will need to make sure that your return is proper XML or an error will be thrown]
    3. startTag and endTag are mainly useful when pulling content from another HTML DB page or URL
    4. startTag and endTag have no effect if the mode is XML
    5. the strings expected for startTag and endTag should be unique in the content returned unexpected results can happen if the string is not unique.

Example