getJSON and variable scope in javascript
Posted
by nillls
on Stack Overflow
See other posts from Stack Overflow
or by nillls
Published on 2010-06-02T18:25:07Z
Indexed on
2010/06/02
18:34 UTC
Read the original article
Hit count: 192
Hi!
In order to make function calls to our back-end php code we've implemented something called an ActionProxy like this:
function ActionProxy(action, input, callback){
$.post("ActionProxy.php?method="+action,
{ data: input},
function(data, textStatus, XMLHttpRequest){
//return data.ResponseWhatever
}
});
The problem we're having is that using data outside the ActionProxy is impossible due to variable scope limitations (we assume), setting
var res = data.ResponseWhatever
or
return data.ResponseWhatever
is pretty futile. How would one handle these responses most appropriately so that functions calling the actionproxy can access the response values?
© Stack Overflow or respective owner