
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2015 02:59 PM
Hello all,
Is there a way to pass value to the callback function when we use GlideAjax.
function onChange (){
var temp = '123';
var x = new GlideAjax ('ABC');
x.addParam ('sysparm_name','123');
x.getXML(callBack,temp);
}
function callBack (response,temp){
alert(temp);
}
Here i want to pass the value of variable temp to the callback function without declaring it as a global variable.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2015 03:39 PM
Hello Ravio,
You can do it with a closure:
function onChange(){
var temp = '123';
var x = new GlideAjax('ABC');
x.addParam ('sysparm_name', '123');
x.getXML( function (response) { callback (response, temp); });
}
function callBack (response, temp){
alert(temp);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 08:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2015 06:48 PM
Not being aware of Edwin's method, I would have done this by adding parameter "sysparm_temp" with the variable temp and returned it back in the Ajax script include.
I can post some code if you would find it helpful, although Edwin's solution is much cleaner.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2015 08:07 PM
Is your code not working?As I remember using the way you have specified

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2015 08:50 AM
Hi Kalai,
The syntax in which i have specified in the question doesn't work.