Yeast engine API documentation

YST.AJAX namespace

YST.AJAX contains a set of methods that allow the establishment of AJAX interactions between a Yeast template and a server. The design of YST.AJAX allows developers not only to use this API in Yeast templates. YST.AJAX is a general purpose API.

You can read more details about the Yeast templates and AJAX in this link, or in the Template Tutorial.

 

Function summary
Back to top

YST.AJAX.createXHR ()

Creates a XMLHttpRequest object taking into account the different browser peculiarities.

YST.AJAX.request (reqParams: YST_AJAX_Request)

Use this function to perform an AJAX request to the server.

YST.AJAX.setTrace (trace: boolean)

At the beginning of the Yeast Template processing, the Yeast engine may show a red box in the upper right corner of the browser window indicating that the processing is in progress.

YST.AJAX.update(id: String)

Call this method to perform the re-processing of a Yeast element whose identifier is sent as parameter.

Function detail
Back to top

YST.AJAX.createXHR ()

Creates a XMLHttpRequest object taking into account the different browser peculiarities.


YST.AJAX.request (reqParams: YST_AJAX_Request)

Use this function to perform an AJAX request to the server. Sending the suitable parameters you can automate the creation of the XMLHttpRequest object, the URL making, the contact to the server, the new data evaluation and the Yeast element re-processing.

This method allows you to configure a number of connection parameters, such as the request synchronicity, the use of the browser cache and encoding issues among others.

Moreover it will allow you to specify functions for the handling of connection errors, and for the performing of extra actions before or after the response has been evaluated.

In fact the YST.AJAX.request function is a general purpose AJAX function that can be used in any application.

Internally YST.AJAX.request uses a XMLHttpRequest object to contact the server.

parameter   type description
reqParams YST_AJAX_Request

This object is used as a container for the parameters used to configure the request.

Among these parameters you will find the service URL (mandatory), the http parameters, the list of element ids to be re-processed, and so on.

Follow this link to see the complete list of parameters.

Usage

Calls to this function should appear in the code of the event handlers that trigger the AJAX interactions. For example, a typical use of the function could be:

<a href"#" onClick="YST.AJAX.request( ... );return false;">Click me!</a>

In order to configure the call you must provide an object with some of the properties described in YST_AJAX_Request.

<a href"#" onClick="YST.AJAX.request  (
                    { 
                      url:        "http://x.y.z/a",
                      updateIds:  ['id1','id2'],
                      queryForm:  document.getElementById("form1"),
                      avoidCache: false,

                      preUpdate:  function(resp) 
                      {
                        data1 = 0;
                        array1 = [];
                      },

                      onError: function(code, msg) 
                      {
                        alert("Error  ("+code+"):"+msg);
                      }
                    } ); return false;">Click me!</a>
							


YST.AJAX.setTrace (trace: boolean)

Use this function to configure YST.AJAX.request so that it alerts you with messages about the request progress

parameter   type description
trace boolean  

YST.AJAX.update (id: String)

Call this method to perform the re-processing of a Yeast element whose identifier is sent as parameter. For a certain Yeast element to be re-processable it must be marked with the yst="ajax" attribute (or yst="live").

parameter   type description
id String HTML identifier of the Yeast element to be re-processed