OK, Derrell and Jim, I thought I'd give you guys first crack at this,
but while you both hit upon the variable scope issue, you both failed to
mention that this is also a problem of asynchronism, in addition to that
basic variable scoping issue!
Ingrid, as is common in learning to deal with asynchronous calls, you
are failing to see the big picture with making an asynchronous call such
as this. You can't read the variable from the result of this call right
after you send the call to the backend using the "send()" method. Even
if you resolve the scope issue by using only the global variable, it
will likely not be set yet by the time line 21 tries to read the
returned result, as it doesn't get set until the "completed" event fires
some time after the asynchronous call.
In summary, asynchronous means your calling routine doesn't stop running
and wait for the result. It keeps chugging through after the call, and
the event listener for the "completed" event then manages whatever
actions need to be carried out upon receiving the result. It's
important for you to readjust your thinking to the way asynchronous
calls work and then adjust your code according to the new paradigm of
this coding structure, otherwise you run into timing errors such as
this.
While you can change the type of call for qx.io.remote.Request from
asynchronous to synchronous to avoid the timing issue, this freezes the
web browser's operation until the response arrives - not a good idea in
most cases and strongly discouraged by many on this discussion list.
HTH,
Gene
On Mon, 2009-08-10 at 11:26 -0700, Jim Hunter wrote:
> This is not a qooxdoo issue, it's a simple JavaScript scoping issue.
> Read up on JavaScript scoping and you will see that you are creating
> the var customerid inside the listener. What this means is that once
> you leave the scope of the listener function, that variable get
> destroyed. You need to create a global variable prior to calling the
> listener, then inside the listener set the global variable to be the
> customer id. It will then be available anywhere in your application.
> Or better yet, create a customer class with an ID property, create an
> instance of that class to hold the current customer information you
> are dealing with and set that instances ID to the returned value of
> the listener. This way, your code would possibly work with more then
> one customer without clobbering the ID.
>
> Jim
>
>
> On Mon, Aug 10, 2009 at 11:15 AM, Ingrid Lohmann <[email protected]>
> wrote:
>
> Hi all,
>
> I'd like to write a login procedure. According to what a user
> puts in input boxes(__tpassword,__tuser)
> a qx.io.remote.Request is generated. If the login data is
> correct, the request should return
> the customerid of the user, but here the prob starts. The
> customerid in line 13 is different to the one in line 21.
> In line 13 the correct customerid is alerted whereas in line
> 21 the customerid is 0 again.
>
> Think this is stupid beginner question, but I need a way to
> get data from the DB I can
> process within the program. Can say whats wrong here or give
> me ressources /howtos in the net
> in order to overcome this prob ...Thank you !
>
> 1 checkInput : function()
> 2 {
> 3 var customerid = 0;
> 4 param =
> "http://www.ourdomain.net/source/php/auth.php?pass="
> +this.__tpassword.getValue()+"&login="+this.__tuser.getValue
> ();
> 5
> 6 var auth_proc = new qx.io.remote.Request(param);
> 7 auth_proc.addListener("completed",
> 8 function(e){
> 9 try {
> 10 var content = e.getContent();
> 11 if (content.length > 0){
> 12 var customerid = qx.util.Json.parse
> (content);
> 13 alert(customerid);
> 14 }
> 15 }catch (e){}
> 16 qx.bom.Cookie.set
> (newversion.Application.COOKIE_KEY , customerid );
> 17 alert(customerid);
> 18 }
> 19 );
> 20 auth_proc.send();
> 21 alert(customerid)
> 22 }
>
> regards,
>
> Poc
> --
> Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla
> Firefox 3 -
> sicherer, schneller und einfacher!
> http://portal.gmx.net/de/go/chbrowser
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal
> Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment
> - and focus on
> what you do best, core application coding. Discover what's new
> with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________ qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel