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

return value from Ajax callback

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

    return value from Ajax callback

    Hi

    I watched all the nice movies (66) about Ajax callbacks but all these steps show how to get data TO the server.


    I want to do an SQL query from the page. I don't know if an SQL query is possible at all directly through Java script, so I try to do it with
    an Ajax callback. (similar to Video 91).

    But how do I get any results from the query back into a grid. I am not even talking about many data sets in an array, but only a True/False that
    shows me if a Phone number already exists. (I don't want to do this with the field validation, because I want a real time validation and not onSubmit).

    So the function declaration is:

    function Does_Phone_Nbr_Exist as c (e as p)

    ...Do the query...

    Does_Phone_Nbr_Exist = "Y"
    end function



    It is defined to return a character, but where can I get the return value from?

    Thanks a lot!

    #2
    Re: return value from Ajax callback

    You have to return javascript to the browser, not just a value. This had me stumped for a long time as well. Say you did return a value of "Y" to the browser, the browser would not know what to do that that value -- the browser is just sitting there, idle really. So you cause your callback to return javascript and it can update your screen, insert values in any field, popup an alert, etc.

    So in your example:

    Does_Phone_Nbr_Exist = "alert('Y');" - this would popup an alert with the letter "Y"
    Does_Phone_Nbr_Exist = "alert('Yes the number exists');" - this would popup an alert with that message
    Does_Phone_Nbr_Exist = "{grid.object}.setValue('D','HASNUMBER','Y');" - would put "Y" in the field named hasNumber, assuming the request came from a Detail View.

    You can get the exact syntax for js like the last one by going to any onClick event, add a New Action, pick in-line Javascript, pick Insert method...

    If you are new to this, you will need to expirement or ask more questions after you get a start.
    Steve Wood
    See my profile on IADN

    Comment


      #3
      Re: return value from Ajax callback

      Hi Eriks,

      Have you seen Bob Moore's videos on calling stored procedures? http://www.screencast.com/users/remo...re%20Tutorials
      Not sure if it's exactly what you're trying to do but it may also be helpful.

      Stephen
      Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

      Comment


        #4
        Re: return value from Ajax callback

        Thanks Steve, that did help, and I also looked at the movie Stephen!

        One more thing though to this issue:

        My call to the Ajax callback looks like:

        var Phone_Exists='N';
        alert(Phone_Exists);

        {grid.Object}.ajaxCallback('G','{Grid.RowNumber}:all','Does_Phone_Nbr_Exist','','_getData=true');

        alert(Phone_Exists);


        My Server side XBasic function is:

        function Does_Phone_Nbr_Exist as c (e as p)

        // figure out if phone number exists code ( SQL query)

        // If Yes, return:
        Does_Phone_Nbr_Exist = "Phone_Exists='Y'"
        end function


        it runs without errors, but I get the alert "N" twice.

        Why is Phone_Exists='Y' not executed?

        Thanks

        Eriks

        Comment


          #5
          Re: return value from Ajax callback

          I'm no expert, but don't you need an if statement in your javascript?
          Carol King
          Developer of Custom Homebuilders' Solutions (CHS)
          http://www.CHSBuilderSoftware.com

          Comment


            #6
            Re: return value from Ajax callback

            You need to add a semicolon e.g. "Phone_Exists='Y';" to make it a valid javascript expression
            Frank

            Tell me and I'll forget; show me and I may remember; involve me and I'll understand

            Comment


              #7
              Re: return value from Ajax callback

              Why is Phone_Exists='Y' not executed?
              It won't do anything, but what do you expect it to do? What do you mean by not executed?
              Steve Wood
              See my profile on IADN

              Comment


                #8
                Re: return value from Ajax callback

                I think he means the value 'Y' is not being assigned to the variable 'Phone_exists' but I wonder if that is possible because of the variable scope ? 'Phone_exists' is declared in the function thus it is local. I need to test this.
                Frank

                Tell me and I'll forget; show me and I may remember; involve me and I'll understand

                Comment


                  #9
                  Re: return value from Ajax callback

                  What you want is this (this is not exactly how I would write the callback but it illustrates a point):

                  onClick event: {grid.Object}.ajaxCallback('G','{Grid.RowNumber}','Does_Phone_Nbr_Exist','','_getData=true');

                  Callback:
                  function Does_Phone_Nbr_Exist as c (e as p)

                  dim Phone_Exists as L = .f. ' default to No

                  // figure out if phone number exists code ( SQL query)
                  //set Phone_Exists to true or false

                  If Phone_Exists = .t.
                  Does_Phone_Nbr_Exist = "alert('Yes Phone Exists');"
                  else
                  Does_Phone_Nbr_Exist = "alert('No Phone does not exists');"
                  end if
                  end function

                  You DO NOT return a value for Phone_Exists to browser. The javascript alert is handled as part of the callback function.

                  I don't know why you had ":all" following the the Grid.Rownumber, I assume this is on a button on a grid row and you want to inquire about a number on THAT row.
                  Steve Wood
                  See my profile on IADN

                  Comment


                    #10
                    Re: return value from Ajax callback

                    Hi Steve,

                    Clipper is correct.

                    the alert is clear to me but I not just want to alert the user but also do something if duplicates exist. (Opening another window to show him the duplicate customer entries in another grid).
                    So I need to get a variable or something back that will allow me to take action beyond an alert.

                    (The same would be true for another problem I am having:

                    If you do a callback to do a server side XB SQL query, how do you get the result(s) back into the local Java program)

                    Thanks

                    Eriks

                    Comment


                      #11
                      Re: return value from Ajax callback

                      I've never been successful taking the results of a callback and using them in a subsequent task in the Action Javascript window, I don't know if you can. Everyone I work with does all of that in the return from the callback, just like the Alert example. There is an inherent problem in making a callback and then trying to run some additional task. The problem is the callback will finish and return control to the browser BEFORE the xbasic or sql script in the callback is complete. This has been proven over and over.

                      Using your example, if you tried to send back the results of the callback and then fire the alert as a subsequent task, it will never work because the alert will fire before the xbasic script determined the value for your variable.
                      Steve Wood
                      See my profile on IADN

                      Comment


                        #12
                        Re: return value from Ajax callback

                        Steve is right, that's why they call it ajax; asynchronous. I keep forgetting that all the time.
                        Frank

                        Tell me and I'll forget; show me and I may remember; involve me and I'll understand

                        Comment


                          #13
                          Re: return value from Ajax callback

                          Great.

                          Now that this is clear:

                          How can I find out if a certain Phone number is already in the database and base some actions onto the result?

                          Comment


                            #14
                            Re: return value from Ajax callback

                            I think the videos in section 85 here (http://news.alphasoftware.com/V10Preview/videos.htm) will help you, Eriks. These were some videos made after Selwyn helped me quite a bit with doing a lookup to my database to see if a record existed in a table before I deleted something in a parent table.
                            Carol King
                            Developer of Custom Homebuilders' Solutions (CHS)
                            http://www.CHSBuilderSoftware.com

                            Comment


                              #15
                              Re: return value from Ajax callback

                              Thanks Carol,

                              that helped a lot!

                              Comment

                              Working...
                              X