Skip to content

Commit 33bd214

Browse files
Client script multi value ajax call without JSON (#810)
* Fetch Multiple Values in GlideAjax without JSON This code snippet allows to receive multiple response from server side to client side using GlideAjax without using the complex JSON format * Create README.md * Delete Fetch Multiple Values in GlideAjax without JSON directory * Fetch Multiple Values in GlideAjax without JSON This code snippet allows to receive multiple response from server side to client side using GlideAjax without using the complex JSON format. * Create README.md
1 parent f57aa40 commit 33bd214

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function onLoad() {
2+
3+
var ga = new GlideAjax("TestScriptInclude");
4+
ga.addParam("sysparm_name", "getCalculations");
5+
ga.addParam("sysparm_input1", 50);
6+
ga.addParam("sysparm_input2", 10);
7+
ga.getXML(function(response) {
8+
var ele = response.responseXML.documentElement;
9+
10+
var add = ele.getAttribute("add");
11+
var sub = ele.getAttribute("sub");
12+
var mul = ele.getAttribute("mul");
13+
var div = ele.getAttribute("div");
14+
15+
var message = "";
16+
message = message + "Addition: " + add + "\n";
17+
message = message + "Subtraction: " + sub + "\n";
18+
message = message + "Multiplication: " + mul + "\n";
19+
message = message + "Subtraction: " + div + "\n";
20+
21+
g_form.addInfoMessage(message);
22+
});
23+
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This code snippet allows to receive multiple response from server side to client side using GlideAjax without using the complex JSON format. You can set multiple attributes in server side, and use the same attribute at the client side to receive responses.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var TestScriptInclude = Class.create();
2+
TestScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
getCalculations: function(){
5+
var input1 = Number(this.getParameter("sysparm_input1"));
6+
var input2 = Number(this.getParameter("sysparm_input2"));
7+
8+
var add = input1 + input2;
9+
this.getRootElement().setAttribute('add', add);
10+
11+
var sub = input1 - input2;
12+
this.getRootElement().setAttribute('sub', sub);
13+
14+
var mul = input1 * input2;
15+
this.getRootElement().setAttribute('mul', mul);
16+
17+
var div = input1 / input2;
18+
this.getRootElement().setAttribute('div', div);
19+
},
20+
21+
type: 'TestScriptInclude'
22+
});

0 commit comments

Comments
 (0)