You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

This class lets the client script to execute the code on the server side using the includes.

Complete the following steps to use SimpleAjax

  • Create a SimpleAjax instance, for this you have to call SimpleAjax constructor. The script that involves the class containing the necessary methods should be the argument for the constructor.
  • Call the addParam method with sysparm_name parameter and method name from include part of the script you want to call.

(Optional) Call addParam method more than once to provide other parameters to the script code. Run the code on the server side calling getXML().

addParam(param, value)

Specifies the parameter name and its value to be passed to the server-side function, associated with current SimpleAjax object. You can run addParam more than once with different parameters and values.

Note: The server-side code does not execute until client script will not call getXML().

Parameter(s):

NameTypeMandatoryDefault value
paramStringYN
valueStringYN


Return:

TypeDescription
VoidThis method does not return a value


Example:

addParam
var record_ajax = new SimpleAjax('incidents'); //Call script include
record_ajax.addParam('sysparm_name', 'assignedToMe');

getXML(callback)

Sends the server a request to execute a method and parameters related with current SimpleAjax object. The server processes the request asynchronously. When it's ready, results are returned via the function specified as a callback. 


Return:

TypeDescription
VoidThis method does not return a value.


Example:

getXML
var record_ajax = new SimpleAjax('incidents');  //Call script include
record_ajax.addParam('sysparm_name' , 'assignedToMe');

record_ajax.getXML(callback);

function callback(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  console.log(answer);
}

  • No labels