GlideAjax - Client
-
- UpdatedAug 1, 2024
- 5 minutes to read
- Xanadu
- API reference
The GlideAjax class enables a client script to call server-side code in a script include.
To use GlideAjax in a client script, follow these general steps.
- Create a GlideAjax instance by calling the GlideAjax constructor. As the argument to the constructor, specify the name of the script include class that contains the method you want to call.
- Call the addParam method with the sysparm_name parameter and the name of the script-include method you want to call.
- Optional. Call the addParam method one or more times to provide the script-include code with other parameters it needs.
- Execute the server-side code by calling getXML().
Note: getXML() is the preferred method for executing the code, because it is asynchronous and does not hold up the execution of other client code. Another method, getXMLWait(), is also available but is not recommended. Using getXMLWait() ensures the order of execution, but can cause the application to seem unresponsive, significantly degrading the user experience of any application that uses it. getXMLWait() is not available to scoped applications.
Example
GlideAjax - GlideAjax(String class_name)
Constructor for GlideAjax.
Name | Type | Description |
---|---|---|
class_name | String | The name of the server-side class that contains the method you want to execute. |
Example
In this example, a client script sets the user to Fred Luddy and then calls a script include to get their manager.
GlideAjax - addParam(String parm_name, String parm_value)
Specifies a parameter name and value to be passed to the server-side function associated with this GlideAjax object.
Name | Type | Description |
---|---|---|
parm_name | String | The name of the parameter to pass. (The name must begin with the
sysparm_ .) |
parm_value | String | The value to assign to parm_name. |
Type | Description |
---|---|
void |
Example
In this example, a client script sets the user to Fred Luddy and then calls a script include to get their manager.
GlideAjax - getAnswer()
Retrieves the results from a server-side method called from the client via getXMLWait().
Name | Type | Description |
---|---|---|
none |
Type | Description |
---|---|
void | The result returned by the server-side method previously called with getXMLWait(). |
GlideAjax - getXMLAnswer(Function callback, Object additionalParam, Object responseParam)
Calls the processor asynchronously and gets the answer element of the response in XML format.
Name | Type | Description |
---|---|---|
callback | Function | Callback function. The function receives the answer element of the response in XML format as an argument. |
additionalParam | Object | Optional. Name-value pair of additional parameters. |
responseParam | Object | Optional. Second argument for the callback function. |
Type | Description |
---|---|
void |
Example
Returns the number of attachments
GlideAjax - getXML(Function callback)
Sends the server a request to execute the method and parameters associated with this GlideAjax object.
The server processes the request asynchronously and -- when ready -- returns the results via the function specified as the callback_function.
Name | Type | Description |
---|---|---|
callback | Function | The name of the callback function to process the results returned by the server. |
Type | Description |
---|---|
void |
Example
GlideAjax - getXMLWait()
Sends the server a request to execute the method and parameters associated with this GlideAjax object.
Name | Type | Description |
---|---|---|
none |
Type | Description |
---|---|
void |