Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Getting a JavaScript variable value from ajax callback?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Getting a JavaScript variable value from ajax callback?

    I want to evaluate some condition in Javascript using an XBasic ajax callback function, and then have Javascript take action based on the value that was calculated in the XBasic code.

    Let's say I have some javascript code, such as:

    Code:
    var testvar='1';
    {grid.Object}.ajaxCallback('G','{Grid.RowNumber}:all','isRowLocked','','');
    alert(testvar);
    The isRowLocked XBasic function returns something like this:

    Code:
    isRowLocked = "testvar = '2';"
    However, back in my Javascript, after the ajax call, alert(testvar) still echoes back '1' rather than '2'.

    What am I missing here? I assume it has to do with variable scoping or the asynchronous callback somehow, and if so, how can I change a javascript var value in the XBasic return JS code, or is it even possible? Do I have to use a session variable for this? What would that code look like? If this is not possible, how could I go about doing this?

    Thank you for any ideas you might have.

    Thanks!

    #2
    Re: Getting a JavaScript variable value from ajax callback?

    Found the answer in video D66.

    Comment


      #3
      Re: Getting a JavaScript variable value from ajax callback?

      I'll take it back: NO, the answer in video D66 works ONLY in dialogs, not in grids, contrary to what the video states multiple times. I was able to replicate the video setup on dialogs where everything works as advertised, but this approach simply does not work on grids.

      What I'm trying to do is this:
      JS: initialize a state variable X='N/A'
      run AjaxCallBack
      XB: set state variable X='Yes' or 'No'
      JS: see what state variable X contains (should not be 'N/A' any more)

      I've tried all kinds of tricks with {grid.object}.setStateInfo() and getStateInfo() but to no avail. XBasic can't seem to change the value of X, even if it returns a properly formatted setStateInfo() -JS command.

      Any ideas?

      Comment


        #4
        Re: Getting a JavaScript variable value from ajax callback?

        In your xbasic function, assuming you are using e,
        try e._state.testvar = "2"
        Gregg
        https://paiza.io is a great site to test and share sql code

        Comment


          #5
          Re: Getting a JavaScript variable value from ajax callback?

          Pertti,
          You are forgetting that AJAX calls are Asynchronous. You should probably google what AJAX is all about to get a full understanding.
          Thus, any js that immediately follows your initial callback call will be processed IMMEDIATELY, and therefore long before the js code is returned from the callback.
          Therefore, you should return all js code from within the callback itself.
          e.g.
          isRowLocked = "var testvar = '2'; alert(testvar);"

          Comment


            #6
            Re: Getting a JavaScript variable value from ajax callback?

            Andy,

            That's true, having worked so long with systems that maintain state, it is easy to forget how ajax operates. Thanks for the reminder and the code snippet.

            Comment


              #7
              Re: Getting a JavaScript variable value from ajax callback?

              My testing shows the state variable being changed in the xbasic function,
              but I can't find the way to access the state variable via javascript.
              I have 1 button to set the state variable via xbasic, and a seperate button
              to display the state variable via javascript, but I keep getting an alert that
              says the state variable is undefined.
              Gregg
              https://paiza.io is a great site to test and share sql code

              Comment


                #8
                Re: Getting a JavaScript variable value from ajax callback?

                You can read and write e._state objects in xbasic and javascript like this:

                set in xbasic:
                e._state.testvar = "myvalue"

                read in javascript:
                var v1 = {dialog.Object}.stateInfo.testvar;
                alert('testvar value: ' + v1);

                Or visa versa - set in javascript:
                {dialog.Object}.stateInfo.testvar = 'myvalue';

                read in xbasic:
                dim testvar as c = e._state.testvar

                So, e._state in xbasic becomes {grid/dialog.Object}.stateInfo in javascript.
                Haven't used it in the grid, (that I remember) but I think it works the same way.
                - Dan Hooley
                - Custom Desktop or Web database development -

                Comment


                  #9
                  Re: Getting a JavaScript variable value from ajax callback?

                  Thank you for your response. As also shown in video D66, it works well with dialogs. Based on my own testing, this approach doesn't work at all with grids. Would be nice if it did, though, because I often run into situations where I need to see and change a certain variable value in both client and server.

                  Comment

                  Working...
                  X