Client-side AJAX

The client side of the AJAX call needs to set up the AJAX call and pass the relevant parameters to the server side. Once a response is received from the server, we can use the returned value or values to decide what changes to make. Let's have a look at how the client side of the AJAX call works:

var ajaxCall = new GlideAjax('serverAjax');
ajaxCall.addParam('sysparm_name','getUserLocation');
ajaxCall.addParam('sysparm_user_id', g_form.getValue('caller_id'));
ajaxCall.getXML(ajaxResponse);

function ajaxResponse(response) {
   var answer = response.responseXML.documentElement.getAttribute("answer");
   alert(answer);
}

The preceding example covers the calling of the AJAX call and the return function, based on the results ...

Get Mastering ServiceNow Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.