[Proto-Scripty] unable to set global variable from a new Ajax.request

2011-03-17 Thread Alphonso77
I'm trying to either return a value or set a global variable from
within a function run on the onSuccess event.  I've tried defining an
inline function and setting a global variable, returning a value, and
even defining a separate function that gets called.  The problem is
that the variable is getting erased outside of the function holding
the new Ajax.request object.

I know this has to do with variable scope, but I'm running out of
ideas on how to make the value of my response.responseXML available to
functions outside of the one creating the new Ajax.request.  Any help
you could provide would be greatly appreciated.  Here is my code:

function stakeholderModel(strDataNeeded){
 new Ajax.Request('file_name.php'),
  {onSuccess: function(response) {
   globalVariable = response.responseXML
   },
  parameters: {parm1: parmValue}
 });
}

-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] unable to set global variable from a new Ajax.request

2011-03-17 Thread Walter Lee Davis
Did you try defining the variable in the global scope first? Something  
like this:


var myGlobalVariable

function stakeHolderModule(strDataNeeded){
new Ajax.Request('foo',{parameters:{bar:baz},
onSuccess: function(response){
myGlobalVariable = response.responseXML;
}
});
}

I don't think it's enough to declare it global just by leaving off the  
var keyword when you're already inside an anonymous function.


Walter

On Mar 16, 2011, at 8:30 AM, Alphonso77 wrote:


I'm trying to either return a value or set a global variable from
within a function run on the onSuccess event.  I've tried defining an
inline function and setting a global variable, returning a value, and
even defining a separate function that gets called.  The problem is
that the variable is getting erased outside of the function holding
the new Ajax.request object.

I know this has to do with variable scope, but I'm running out of
ideas on how to make the value of my response.responseXML available to
functions outside of the one creating the new Ajax.request.  Any help
you could provide would be greatly appreciated.  Here is my code:

function stakeholderModel(strDataNeeded){
new Ajax.Request('file_name.php'),
 {onSuccess: function(response) {
  globalVariable = response.responseXML
  },
 parameters: {parm1: parmValue}
});
}

--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.




--
You received this message because you are subscribed to the Google Groups Prototype 
 script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.