I'm having a problem with using server callbacks to web methods within an object in JavaScript...
function myObject() {
this.hello = "hello";
var id = 1;
var name;
this.findName = function() {
alert(this.hello); //Displays "hello"
myServices.getName( id, this.sayHello );
}
this.sayHello = function(name) {
alert(this.hello); //Displays null <-- This is where I'm confused...
alert(name); //Displays the name retrieved from the server
}
this.findName();
}
So when a new myObject
is created, it finds the name and then calls sayHello
once the name has been found.
The service routine works and returns the correct name.
The issue is that after the name is returned from the server and this.sayHello
is called, it doesn't seem to be in the same object (no reference to the same myObject
that we were in when we were finding the name) because this.hello
gives a null
...
Any ideas?