The following code requests information about an object, and then
tries to set a couple class variables based on the data returned from
the request.
var Demo = new Class({
save: function() {
var req = new Request.JSON({
url: "/demos.json",
method: "post",
data: {"demo[name]":this.name,
"authenticity_token":this.auth_token},
onSuccess: function(d) {
this.updateDemo(d.demo.id, d.demo.name);
this.id = d.demo.id;
}.bind(this)
}).send();
},
updateDemo: function(id, name) {
this.id = id;
this.name = name;
}
}
I've got "this" binded properly because I can access the updateDemo
function properly but I can't seem to be able to set variables from
within the updateDemo function, or the onSuccess function.
If I create a demo class and then try and access the "id" variable, it
returns as undefined. What am I doing wrong?
Thanks in advance!