Sei sulla pagina 1di 2

Notes on Glide Ajax.. Please Go through it ..

The wiki article is the most comprehensive document that I am aware of on GlideAjax. GlideAjax
lets you run server side scripts from the client. The GlideAjax client side object and the
AbstractAjaxProcessor script include negotiate the XML request and response. So the
communication looks like this:

Request: Your Client Script => GlideAjax => AbstractAjaxProcessor => Your Script Include
Response: Your Script Include => AbstractAjaxProcessor => GlideAjax => Your Client Script

1. Your client script creates a GlideAjax object and sets parameters in the request XML.
2. Your client script calls getXML (async, client can run other scripts while waiting for a response)
3. AbstractAjaxProcessor (which is inherited by your script include) processes the request message
and hands it off to your Script Include
4. Your script include uses getParameter to read the request, processes the request and uses
setAttribute to generate a response.
5. AbstractAjaxProcessor responds to the client with the XML message generated transparently in
step 4
6. GlideAjax notifies your Client Script that the response has been received by calling the async
function that you passed into the first parameter of the GlideAjax.getXML function

So now lets look at the objects:

Glide Ajax
1. GlideAjax(scriptIncludeName): The GlideAjax constructor takes the name of a Script Include as its only
parameter. This is the Script Include that GlideAjax will use to process the AJAX request.
2. addParam(name, value): Adds parameters to the XML request which can be consumed by the Script Include's
getParamter function. It accepts two parameters, name and value. Name is a string you will use in the
getParamter function to retrieve the value set in the Value parameter.
3. getXML(ajaxResponse): Sends the XML asynchronously, allowing the client to continue processing. The
ajaxResponse parameter should be a function that accepts a single parameter which will contain the response
message. The ajaxResponse function will be called when GlideAjax receives the response from the server.

AbstractAjaxProcessor
The AbstractAjaxProcessor should be inherited by the Script Include used in the GlideAjax
constructor. AbstractAjaxProcessor function calls can then be made within the Script Include by
prefixing with the 'this' keyword.
Example:
1. this.getParameter('name');

1. getParameter(paramName): Returns the value for a parameter with the name passed into the paramName (as
created by GlideAjax's addParam function).
2. newItem(elemName): Creates a new element in the XML response. The element will have the name given in
the elemName parameter. Example: this.newItem('hello'); creates an XML element <hello></hello>. The
function returns the XML element object.

XML Element
XML elements are created by the AbstractAjaxProcessor newItem function call.
Example:
1. var result = this.newItem('result'); // result is an XML Element object <result></result>
1. setAttribute(name, value): Creates an attribute on the XML Element with the name and value
parameters. Example:
1. result.setAttribute('hello', 'world'); // From the previous example will create <result hello="world"></result>

Ajax Response Object


Ajax response object is passed into the ajaxResponse function passed to GlideAjax's getXML
function. The XML can then be accessed via serverResponse.responseXML.
Example (assume ga is a GlideAjax variable):

1. ga.getXML(ajaxRepsonse);
2.
3. function ajaxResponse(serverResponse) {
4. var answer = serverResponse.responseXML; // answer contains the XML response object created in the Script Includ
e
5. }

1. getElementsByTagName(elemName): Gets a client side element object. The elemName refers to the element
name created in the Script Include via the AbstractAjaxProcessor's newItem function. Returns an array of
element objects. Example:
1. var result = responseXML.getElementsByTagName("result"); // Returns an array of elements. The <result hello="worl
d"></result> created in the example above would be returned in an array of 1 item in this case.

Client Side XML Element


1. getAttribute(name): Returns the value for an attribute as set by the Script Include using the setAttribute
function. Example:
1. // Continuing from previous example
2. var i,
3. hello;
4. for (i = 0; i < result.length; i++) {
5. hello = answer.getAttribute("hello"); // Returns the string 'world' as set in the setAttribute example
6. }

Apart from implementation, that is about all there is to GlideAjax. Of course, I focused only on async
but this is the preferred method of handling GlideAjax. Please let us know if you have more specific
questions about the API. I hope this helped.

Potrebbero piacerti anche