Alpha Video Training
Results 1 to 8 of 8

Thread: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

  1. #1
    Member
    Real Name
    Nick
    Join Date
    May 2011
    Location
    Michigan, USA
    Posts
    58

    Default Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    I'm certain that I am doing something fundamentally wrong, but I have been struggling to find it and wanted to ask for help. Of course, I was trying to things more complex but I kept scaling back to find my problem and this is where I am at.

    I have two grids, Grid1 and Grid2. I added a button to Grid1 and added two pieces of Action Javascript to the button's onClick event. The first is an AJAX callback that calls the Xbasic function SetMyVariable.

    Code:
    FUNCTION SetMyVariable AS C ()
    	session.taco = 512
    	SetMyVariable = "alert('session.taco = " + session.taco + "');"
    END FUNCTION
    This works fine, the prompt shows the correct value for the session variable.

    The second part of the onClick event opens Grid2 in an AJAX popup window.

    Grid2 contains a button that has an onClick event that calls an AJAX callback to call the Xbasic function ShowMyVariable.

    Code:
    FUNCTION ShowMyVariableAS C ()
    	ShowMyVariable= "alert('A5.msgBox.hide();session.taco = " + session.taco + "');"
    END FUNCTION
    This one does not work. Generally, I get the error that says session.taco is not defined. Or if the alert works, it says that session.taco is some other value (I have been changing the constant in SetMyVariable to test things).

    I'm guessing this is something seemingly trivial to you guys, but I'm stumped. Any help would be great!

    Thanks!

  2. #2
    Volunteer Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Lexington, KY
    Posts
    1,488

    Default Re: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    It works for me.
    Why does your ajax callback not have the (e as p) in both of the functions? If you created your functions by copying the code that Alpha creates, it should have the (e as p).
    Try adding that as in:
    function SetMyVariable as c (e as p)
    session.taco = 512
    SetMyVariable = "alert('session.taco = " + session.taco + "');"
    end function
    Jay
    Jay Talbott
    Lexington, KY


  3. #3
    Member
    Real Name
    Nick
    Join Date
    May 2011
    Location
    Michigan, USA
    Posts
    58

    Default Re: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    I have the (e as p) in both of them, I just forgot to copy and paste that part in my first post. Would it matter if my Xbasic functions are in an AEX file? When I click the button in Grid2 I get the error "...Property not found session.taco subelement not found."

    I'll play with it some more. Maybe write new functions and create new grids, clear the AEX cache (I have restarted the server several times). Perhaps I'll even write the Xbasic into the grids. Where does that go again?

  4. #4
    Volunteer Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Lexington, KY
    Posts
    1,488

    Default Re: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    That goes in the properties part of the grid under Xbasic functions.
    Sounds like you need to "Gwennify" this. That means you need to take it down to its basic level, and add one variable at a time, and check if each change works.
    Take it a step at time, and don't change two elements at once.
    Hope this helps.
    Jay
    Jay Talbott
    Lexington, KY


  5. #5
    Member
    Real Name
    Nick
    Join Date
    May 2011
    Location
    Michigan, USA
    Posts
    58

    Default Re: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    Well I may have figured out the root cause of my problem, but I'm stuck with how to fix it.

    I went back and re-made the two grids.

    Grid1 has two buttons on it.
    Button1 has an onClick that does an AJAX callback to call the Xbasic function:
    Code:
    FUNCTION SetMyVar as C (e as p)
    	session.taco = 1024
    	SetMyVar = "alert('session.taco = " + session.taco + "');"
    END FUNCTION
    Button2 opens Grid2 in an AJAX popup window.

    Grid2 has a button on it that does an AJAX callback to call the Xbasic function:
    Code:
    FUNCTION ShowMyVar as C (e as p)
    	ShowMyVar = "alert('session.taco = " + session.taco + "');"
    END FUNCTION
    This setup works just fine. If I go to the Xbasic declaration of SetMyVar() and change the value set to session.taco and then click Button1 and then Button2 in Grid1 and then click the button in Grid2 I get the correct messages.

    Here is where I get problems: If I modify the onClick of Button1 (the one on Grid1) to open Grid2 in an AJAX popup as well as do the AJAX callback to set session.taco, then the button on Grid2 that shows the value of session.taco gives me an error that session.taco is not defined of the value it gives me is the previous value I had set to it.

    I think that the problem is that the call to open Grid2 in the AJAX popup executes before the AJAX callback to set session.taco completes, thus Grid2 would have the wrong (or an undefined) value in session.taco. On the other hand, that doesn't seem to make sense. The AJAX callback should always get the value of session.taco from the server, shouldn't it? The alert from Grid1 always has the correct value of session.taco.

    Does that seem like a correct reading of what the problem is? Further, any idea on how to fix it? Is there a way to wait for the AJAX callback to complete before opening the popup window? Or even better, what I really want is a way to send data from Grid1 to Grid2. That is why I was doing the callbacks. My thought was, take what is in the grid, send it to the server and store it in session variables. Then when I need that data while working on Grid2, get it from the session variables. I realize I can open Grid2 in an a5w page and pass the data in Grid1 in the URL, but I would rather not. Any suggestions?

    Thanks for the help Jay!

  6. #6
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,639

    Default Re: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    Trying to run multiple AJAX calls at (nearly) the same time can be fraught with problems.

    First thing to do is to see about setting your values at different times so there's no "competition" with the calls.

    You should be using Firefox with Firebug, which will help you see when callbacks are made.
    -Steve


  7. #7
    Member
    Real Name
    Nick
    Join Date
    May 2011
    Location
    Michigan, USA
    Posts
    58

    Default Re: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    I have Firebug, but I had only been using Live Preview. Firebug shows the events firing in the correct order, but they are working asynchronously so when they complete relative to each other is a different story (correct?). Interestingly, a Live Preview in Firefox works correctly everytime (so far), while Live Previews in IE, Chrome, and Safari suffer the previously described problems.

    I am starting to think that this is just the way things work and I'll have to find some other way to do what I want. I guess just using an a5w page and passing the data along the URL would be acceptable, but not as clean. Anyone remember how to access the GET data that is in the URL from Xbasic?

  8. #8
    "Certified" Alphaholic
    Real Name
    Chris Tappan
    Join Date
    Jun 2009
    Location
    Marietta, GA
    Posts
    1,303

    Default Re: Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows

    I think you could create a second, hidden button set up to open grid2. Then in the AJAX callback, set the variable and return the Javascript needed to call the function in the hidden button.

Similar Threads

  1. Question on AJAX Popup Windows
    By njw1314 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 13
    Last Post: 09-30-2013, 10:49 AM
  2. an explanation of AJAX callbacks
    By Richard Rabins in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 05-25-2011, 11:36 PM
  3. Updating records using Ajax Callbacks
    By BigBoss1 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 02-24-2010, 09:01 AM
  4. Video Tutorial on User Defined Ajax Callbacks
    By Selwyn Rabins in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 02-21-2010, 01:45 PM
  5. AJAX Callbacks off Advanced Buttons
    By Pat Bremkamp in forum Application Server Version 9 - Web/Browser Applications
    Replies: 2
    Last Post: 08-15-2008, 06:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •