Results 1 to 6 of 6
  1. mfive's Avatar
    Posts
    186 Posts
    Global Posts
    193 Global Posts
       #1  
    Ok, I thought I had this down, but now that I'm digging deeper into my code I'm realizing I don't.

    I'm trying to have a variable that I can assign after an AJAX request that's visible in every other function of a specific scene... I'd like to assign the results of an AJAX request to this variable that I can use elsewhere in my code.

    I tried putting it in a model.jsjsjs $file$ $that$ $is$ $in$ $sources$.$js$ $like$ $so$:

    var Data = {
    One : ""
    };

    And then in the onSuccess function of my AJAX request, I assign the results of transport.responseText to my variable, but when I try to assign the result to Data.One it doesn't save it outside of the onSuccess function. I tried using a 'this.One' variable in my scene assistants function, but that variable isn't visible inside of the onSuccess callback to assign it to.

    I know I'm getting results because I can Mojo.Log.info my responseText and it is there.

    What am I doing wrong here!?
  2. #2  
    Try placing the declaration in your scene assistant's function or (for even larger reach) the stage handler. Just be sure you aren't already using the variable Data anywhere (unless you want it to be the same var).
    Author of Exch-Calc, Dog Years, Cat Years and all future creations of Pre-zy Software. Available in the Application Catalog.
  3. mfive's Avatar
    Posts
    186 Posts
    Global Posts
    193 Global Posts
       #3  
    Ken, I still can't get that to work. Thanks for taking a look at my post, though!

    So, here's a little better idea of what I'm trying to accomplish,

    In my scene assistant's function, I declare a variable that I'd like to use "globally" later...

    I declare it like so:
    Code:
    this.variable_name = '';
    Then, in my scene assistant's prototype.setup function I have an Ajax.Request that assigns the responseText to the global variable in an onSuccess or onFailure callback function:

    Code:
    this.variable_name = transport.responseText;
    Then, below that, still in the prototype.setup I have a connectionmanager service request, and in the onSuccess callback function, I'd like to reference my variable. I'm assuming it can't see the variable because it's inside a callback function, no? But, when I try to use my global variable, it comes back as 'undefined'...

    Any other pointers or suggestions?
  4. #4  
    How are you binding the onSuccess event? Because I think you are copying the function out of the object, therefor loosing the 'this' scope.
    My Palm History (in order): IIIe SE, m130, Tungsten|T, m505, Tungsten|T3, Zire 71, m505 (owned two different ones), Zire 72, Tungsten|C, T|X, Treo 650.
    After that I got a Apple iPhone 3G, Palm Pre (GSM), Google Nexus One.
  5. mfive's Avatar
    Posts
    186 Posts
    Global Posts
    193 Global Posts
       #5  
    Quote Originally Posted by xioq View Post
    How are you binding the onSuccess event? Because I think you are copying the function out of the object, therefor loosing the 'this' scope.
    for the Ajax.Request or the connectionmanager service?
  6. #6  
    Whichever you are using for your request.

    - ah wait, you're using both and want to use the response from the Ajax.Request in the ConnectionManager 'onSucces'.

    That's tricky, because of the first A in AJAX. Asyncronous, when you perform your Ajax.Request it doesn't pause and wait til the request is finished, it continues to the next one, to the ConnectionManager. What I'd do here, is don't do anything with the ConnectionManager until the Ajax.Request is finished. So in the onSuccess event of the Ajax.Request - you start the ConnectionManager request.
    My Palm History (in order): IIIe SE, m130, Tungsten|T, m505, Tungsten|T3, Zire 71, m505 (owned two different ones), Zire 72, Tungsten|C, T|X, Treo 650.
    After that I got a Apple iPhone 3G, Palm Pre (GSM), Google Nexus One.

Posting Permissions