GlideAjaxV3 - Client

The GlideAjaxV3 API provides the ability to asynchronously execute server-side scripts from a client-side script.

The GlideAjaxV3 API can be used in client-side scripts using ListV2 and ListV3 APIs.

GlideAjaxV3 - addParam(String name, String value)

Set a name-value pair to be sent to the processor.

Table 1. Parameters
Name Type Description
name String The name of the parameter. This usually has the prefix 'sysparm_'.
value String The parameter value.
Table 2. Returns
Type Description
void

GlideAjaxV3 - getJSON(Function callback)

Call the processor asynchronously and get the answer element of the response in JSON format.

Table 3. Parameters
Name Type Description
callback Function The callback function. The function receives the answer element of the response as a JSON object.
Table 4. Returns
Type Description
void

GlideAjaxV3 - getParam(String name)

Returns the value of the specified parameter.

Table 5. Parameters
Name Type Description
name String The name of the parameter to return.
Table 6. Returns
Type Description
String The specified parameter's value.

GlideAjaxV3 - getParams()

Returns the name-value pairs for the request.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
Object The request's name-value pairs.

GlideAjaxV3 - getProcessor()

Returns the server-side script that the request is going to use.

This returns the 'sysparm_processor' parameter.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
String The value of the request's sysparm_processor parameter.

GlideAjaxV3 - getURL()

Returns the target URL.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
String The URL where the Ajax request will be sent.

GlideAjaxV3 - getXML(Function callback)

Call the processor asynchronously and get the response in XML format.

Table 13. Parameters
Name Type Description
callback Function The callback function. The function receives the response as an argument.
Table 14. Returns
Type Description
void

GlideAjaxV3 - getXMLAnswer(Function callback)

Call the processor asynchronously and get the answer element of the response in XML format.

Table 15. Parameters
Name Type Description
callback Function The callback function. The function receives the answer element of the response in XML format as an argument.
Table 16. Returns
Type Description
void
function updateAttachmentCount(sysid) {
    var ga = new GlideAjax('AttachmentAjax');
    ga.addParam('sysparm_type', 'attachmentCount');
    ga.addParam('sysparm_value', sysid);
    ga.getXMLAnswer(numberOfAttachments, null, sysid); // callback: numberOfAttachments
}

function numberOfAttachments(answer, sysid) {
	// we want to know there are 5 attachments, not 5.0 attachments
	var number = parseInt(answer);
	var buttons = $$('.attachmentNumber_' + sysid);
	if (buttons[0] == undefined)
		$('header_attachment_list_label').down().innerHTML = number;
	else {
		for (var i = 0; i < buttons.length; i++) {
			buttons[i].innerHTML = number;
		}
	}
}

GlideAjaxV3 - GlideAjax(String processor)

Creates an instance of the GlideAjaxV3 class.

Table 17. Parameters
Name Type Description
processor String The name of the processor (server-side script) to call.
Table 18. Returns
Type Description
void

GlideAjaxV3 - GlideAjax(String processor, String targetURL)

Creates an instance of the GlideAjaxV3 class.

Table 19. Parameters
Name Type Description
processor String The name of the processor (server-side script) to call.
targetURL String (Optional) Override the xmlhttp processor url. If this parameter is not specified, the default is xmlhttp.do.
Table 20. Returns
Type Description
void

GlideAjaxV3 - setErrorCallback(Function callback)

Sets a callback function to be called if the Ajax request fails.

Table 21. Parameters
Name Type Description
callback Function The function to be called if the Ajax request fails. The callback function has one parameter, the XMLHttpRequest object.
Table 22. Returns
Type Description
void

GlideAjaxV3 - setProcessor(String serverScript)

Sets the request's server-side script. The server-side script is also called the processor.

This sets the 'sysparm_processor' parameter.

Table 23. Parameters
Name Type Description
serverScript String The server-side script (processor) to receive the request.
Table 24. Returns
Type Description
void