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

passing JSON from Xbasic function to javascript

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

    passing JSON from Xbasic function to javascript

    Below is code that pulls data off my dialog (lat and lngs) and uses them to build the starting, stopping, and waypoints to be used in a google maps api call (right now using jQuery's getJSON but there is issues using this so wanting to do the call using xBasic).

    Code:
            var allLat = {dialog.Object}.harvestRepeatingSectionColumn('lat','\n');
    	var allLng = {dialog.Object}.harvestRepeatingSectionColumn('lng','\n');
    	
    	var aLat = allLat.split('\n');
    	var aLng = allLng.split('\n');
    	
    	var txt = [];
    
    	for(var i = 1; i <= aLat.length ; i++) {
    		txt.push(aLat[i-1] + ',' + aLng[i-1]);
    	}
    	
    	var last = txt.length - 1;
    		
    	var waypoints = [];
    	
    	
    		for(var i = 1; i<last; i++){
    		waypoints.push(txt[i]);
    		
    		}
    	
    		
    		waypoints = waypoints.join('|')
    
    
                   var $jq = jQuery.noConflict();
    		
    		 $jq.getJSON('http://maps.googleapis.com/maps/api/directions/json?origin=' + txt[0] + '&destination=' + txt[last] + '&waypoints=' + waypoints + '&sensor=false',function(results){
    I want implement this part of my code in an xBasic function that will be called using an ajax callback in action javascript on a button allowing me to get the JSON and then I want to pass this JSON back to a javascript function to do the parsing (as I have about 5000 lines of code here and don't want to try to convert this to xBasic). Can someone just get me started on how I will harvest data from the repeating section and then build the necessary array (including joining the waypoints array with this character '|' as this is necessary for the goggle api call).

    Thanks!

    Jmo

    #2
    Re: passing JSON from xBasic function to javascript

    As far as I can tell this is not feasible as the xBasic function can't read controls from browser, is this correct? If this is the case is there a way to take that url I've created, put it in a variable, and then do an ajax callback of an xBasic function passing in that url as a variable?

    Comment


      #3
      Re: passing JSON from xBasic function to javascript

      Josh, I've read this a few times, not sure what you need.

      Have you considered:

      {Dialog.Object}.ajaxCallback('','',xbasicFunction,'' [,additionalData [,optionsObject]])

      and

      See video # M58 re: the state object and variables
      -Steve
      sigpic

      Comment


        #4
        Re: passing JSON from xBasic function to javascript

        I am unable to get on my server right now (someone else is developing and I haven't yet created a virtual environment on my Mac to develop locally), but I do believe that is what I am looking for. Just to be sure, with that call I am able to call the xBasic function I want to run and can pass in my url as a character variable in the additional data part? Thanks!

        Comment


          #5
          Re: passing JSON from xBasic function to javascript

          Yeah, it'll take anything. From the example:

          Code:
          {dialog.Object}.submit();
          //Include an optional submitType value and additional data
          {dialog.Object}.submit('type1','var1=alpha&var2=beta');
          So you have name/value pairs. If your name is "var1" then your Xbasic function will have an "e.var1" variable to work with.
          -Steve
          sigpic

          Comment


            #6
            Re: passing JSON from xBasic function to javascript

            I have the URL passing into the xbasic function which I am calling using the Ajax callback action JavaScript (url is being built and returned with a javascript function). Below is my code and the way it works is a button calls getJson(); and the 'ajaxJson' action gets the returned value from urlBuild().

            Code:
            function getJson () {
            
            {dialog.object}.runAction('ajaxJson');
            
            }
            
            function urlBuild () {
            
                 return "varurl=http://maps.googleapis.com/maps/api/[COLOR="#FF0000"]directions[/COLOR]/json?origin=Huntsville,AL&destination=Atlanta,GA&sensor=false";
            }
            Code:
            function getdata as c (e as p)
            
            dim url as c
            dim txt as c
            dim p as p
            url = e.varurl + "&destination=" + e.destination + "&sensor=" + e.sensor
            txt = http_get_page2(url)
            p = json_parse(txt)
            
            dim distance as c
            distance = p.routes[1].legs[1].distance.value
            
            dim js as c
            js = "$('msg1').innerHTML='" + distance + "';"
            
            getdata = js
            
            end function

            If I post "url" to the msg1 div it shows up exactly how it should, however when I post distance it tells me that p.routes[] subelement doesn't exist (however I know it does)? I also tried to post "txt" to msg1 and I get a "string constant not terminated" error? To test this without using the javascript or the building of the url variable I used the code below (with a different button that just did the ajax callback)

            Code:
            function xb as c (e as p)
            
            dim url as c
            dim txt as c
            dim p as p
            url = "http://maps.googleapis.com/maps/api/[COLOR="#FF0000"]directions[/COLOR]/json?origin=Huntsville,AL&destination=Atlanta,GA&sensor=false"
            txt = http_get_page2(url)
            p = json_parse(txt)
            
            dim distance as c
            distance = p.routes[1].legs[1].distance.value
            
            dim js as c
            js = "$('msg1').innerHTML='" + distance + "';"
            
            getdata = js
            
            end function
            I get the same errors as above when using this code, does anyone see anything wrong with either the original code or the testing code that would cause for these errors? As a note I am doing this through remote access to the server (not on my local machine) but I don't think this would make a difference. Thanks for the help!
            Last edited by lilmofo812; 11-13-2013, 12:38 AM. Reason: In red is what I was missing in my code (forgot the 's' on directions) working now!

            Comment


              #7
              Re: passing JSON from xBasic function to javascript

              Again, I'm not sure what your question is, or exactly what problem you're having. I used the last example in your post, and it worked well but with one exception.

              If you change

              Code:
              getdata = js
              to

              Code:
              xb = js
              The static text object that I gave a div of "msg1" filled with the distance.
              -Steve
              sigpic

              Comment


                #8
                Re: passing JSON from xBasic function to javascript

                Originally posted by Steve Workings View Post
                Yeah, it'll take anything. From the example:

                Code:
                {dialog.Object}.submit();
                //Include an optional submitType value and additional data
                {dialog.Object}.submit('type1','var1=alpha&var2=beta');
                So you have name/value pairs. If your name is "var1" then your Xbasic function will have an "e.var1" variable to work with.
                Actually, you will have

                e.rv.var1

                Comment

                Working...
                X