David,
DWR makes asynchronous calls.
Remote.doSomething(callMetaData);
alert(someObject.privateVar); // "Private variable from hell" which I want
to be Hello
someObject.privateVar is going to be "Private variable from hell" until the
remote call has been executed and returned, thus the callback function.
Because this call is asynchronous my guess is that your alert (the one
following your remote call) is being displayed before the call has
completed.
Original Message:
-----------------
From:
David.Luecke@...
Date: Wed, 23 Apr 2008 18:48:35 +0200
To:
users@...
Subject: AW: [dwr-user] Getting data from a callback
Hi David.
Thanks for your reply. I read the page a few times before because I thought
it a scoping issue, too (in Java you can overwrite member variables with
local variables, too).
I now switched to 3.0M1 and got the example working but it's the same issue
again (probably I'm doing something terribly wrong...):
(function() {
someObject = {};
someObject.privateVar = "Private variable from hell";
someObject.callbackFunction = function(dataFromServer)
{
this.privateVar = "Hello world";
alert(this.privateVar); // "Hello world"
}
})();
var callMetaData = {
callback: someObject.callbackFunction,
scope: someObject
};
Remote.doSomething(callMetaData);
alert(someObject.privateVar); // "Private variable from hell" which I want
to be "Hello world" oder dataFromServer or whatever
Do I have to use another scope?
Greetings
David
-----Ursprüngliche Nachricht-----
Von:
david@... [mailto:
david@...]
Gesendet: Mittwoch, 23. April 2008 17:22
An:
users@...
Betreff: RE: [dwr-user] Getting data from a callback
This is a scoping issue. Please read this:
http://getahead.org/dwr/browser/extradataOriginal Message:
-----------------
From:
David.Luecke@...
Date: Wed, 23 Apr 2008 17:14:09 +0200
To:
users@...
Subject: [dwr-user] Getting data from a callback
Hi.
I'm quite new to DWR and I really like it, but I think I have a problem
with the JavaScript part ;)
How can I get the return values of a callback into JavaScript "global"
variables?
I can read variables in the callback function but cannot modify them.
E.g.:
{
this.test = "Hello";
var obj = this;
var callbackfunc = function(arg)
{
alert(obj.test); // alerts "Hello"
obj.test = "Test";
// or obj.test = arg;
alert(obj.test); // alerts "Test"
}
Remote.doSomething(callbackfunc);
alert(obj.test); // alerts Hello
}
Will always alert "Hello" and I don't understand why
or how I could get at the return values from the outside at all.
Thanks a lot in advance
Regards
David
--------------------------------------------------------------------
mail2web.com - Enhanced email for the mobile individual based on Microsoft®
Exchange -
http://link.mail2web.com/Personal/EnhancedEmail---------------------------------------------------------------------
To unsubscribe, e-mail:
users-unsubscribe@...
For additional commands, e-mail:
users-help@...
---------------------------------------------------------------------
To unsubscribe, e-mail:
users-unsubscribe@...
For additional commands, e-mail:
users-help@...
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://link.mail2web.com/mail2web---------------------------------------------------------------------
To unsubscribe, e-mail:
users-unsubscribe@...
For additional commands, e-mail:
users-help@...