var result = liveballScriptlet(1, "json", 'data1=' + val1 + '&data2=' + val2);
There are three parameters in this function:
- “1” represents the scriptlet id. To obtain the scriptlet id, navigate into the scriptlet editor in ion and view the URL in your browser window. The sscID parameter value is what you’ll use as the first parameter in the liveBallScriptlet function.
- The second parameter defines the scriptlet response content type. For example, you'd specify "json" as the content type if that is format the scriptlet will return.
- The third parameter is optional and can be leveraged to save data to the respondent prior to invoking the scriptlet.
Let's say you have a server scriptlet that calculates the sum of x and y that you seek to invoke from page-level script. For example:
return respondent.x + respondent.y;
If this scriptlet's id is 10, below is an example that passes x and y into the scriptlet to return the sum:
var x = 1; var y = 2; var sum = liveballScriptlet(10, "text/plain", 'x=' + x + '&y=' + y);