I have a JS class inside which I am instantiating a goog.net.XhrIo object. Now I can get all the stuff I need from that JS variable, the problem is whenever I try to assign values to an instance variable of the “parent” class, I get an undefined error. I assume this is a scoping problem, but I don’t know how to deal with it.
I am using the Google Closure Library.
The code can be found at:
I am trying to store all the result of the POST request inside a this.items object/array. The line number is 270. If you are looking at this in your browser, search for “console.log(this.mainView);” and it will take you straight to where the problem is.
goog.net.XhrIo.send(this.URL+'/action.url.php', function(e){
var items = new Object();
items = e.target.getResponseJson();
for(var x in items)
{
var currentName;
var currentCat;
if(items.hasOwnProperty(x))
{
currentName = items[x].name;
currentCat = items[x].categories;
}
var x = goog.dom.createDom('div', {
}, currentName, currentCat);
console.log(this.mainView);
}
return e;
},'POST', 'action=getUserData');
Try to bind the handler to the object with
goog.bind: