Before using AJAX you have to make several decisions. First you must decide which AJAX strategy you want to use.
PTFactory>>request— The requestor does not send anything back to the client. It solely sends a request and pushes data to the server.
PTFactory>>updater— The updater updates a single part of the page. You need to provide the ID of the DOM element to update and a callback block that expects one parameter to render the partial XHTML on.
PTFactory>>periodical— The periodical updater is an updater that is periodically executed. Additionally you need to specify an update frequency.
After having chosen the AJAX strategy you might want to specify additional options and declare state that should be transmitted to the server. The most common ones are:
PTAjax>>triggerForm:— Serialize a complete form and trigger all its associated callbacks. Note that the callbacks of submit buttons are ignored to preserve consistency, use the callback to trigger specific code evaluation.
PTAjax>>triggerFormElement:— Serialize a form ”element” such as a text input field and triggers its associated callback. Note that this does not work for all form elements. For example, check-boxes depend internally on other hidden form elements. Submit-button callbacks are ignored.
Furthermore you might want to register some events to get notified about the state of the AJAX action. The most common events are listed below.
PTAjax>>onSuccess:— Invoked when a request completes and its status code is undefined or belongs to the 200 family.
PTAjax>>onFailure:— Invoked when a request completes and its status code exists but is not in the 200 family.
PTAjax>>onComplete:— Invoked at the very end of a request’s life-cycle, once the request completed, status-specific callbacks were called, and possible automatic behaviors were processed.
The above events and some other AJAX options can also be globally set using
PTResponders. This is useful to define an error handler once for the whole page in case the session expires. The following code snipped displays an error message and triggers a full refresh whenever that happens:
addLoadScript: (html prototype responders