4 Replies Latest reply on May 4, 2010 9:49 AM by ilssac

    reading application varibale from javascript

    ctmkikkeri

      i have a xml in application scope i need to access it in java script. how can we do that. any ideas...

        • 1. Re: reading application varibale from javascript
          ilssac Level 5

          Send the XML data to the client, just like you would send HTML, CSS, JavaScript or anything else the client is expected to use.

           

          Your question is a variation of the classic novice idea that the code running on a Client machine is somehow connected to the code that is running on the server and that somehow these two systems (which could be thousands of miles apart) share a common memory and variables.

          • 2. Re: reading application varibale from javascript
            Dan Bracuk Level 5

            Either cfwddx or toscript() will get you started.  Examples on in the manual for that tag and function.

            • 3. Re: reading application varibale from javascript
              ctmkikkeri Level 1

              well, let me be clear on what i am doing. i am developing a google map for a website. i can read the xml in java script and create the map with info but i want to store the xml in cache and use it instead of xml. so i am trying to us java script to read the application. i am new to javascript and i am not sure how can i use the java script to make it read application variable.

               

              Here is the code which is working fine....now i need to chage this so that i can read the application varibale called xmlcache instead of the mapinfo.xml file...any syntax clue is appricated...

               

               

               

              downloadUrl("xml/mapinfo.xml", function(data) {

               

              var markers = data.documentElement.getElementsByTagName("mapstart");
              if (!markers){
              }else{
                 for (var i = 0; i < markers.length; i++) {
                var type = markers[i].getAttribute("type");
                var cause = markers[i].getAttribute("cause");
                var mapID = markers[i].getAttribute("id");
                var reportTime = markers[i].getAttribute("sTime");
                var estRestore = markers[i].getAttribute("eTime");
                var LatLng = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),
                                                  parseFloat(markers[i].getAttribute("lng")));

               

              and so on.....

              • 4. Re: reading application varibale from javascript
                ilssac Level 5

                ctmkikkeri wrote:

                 

                i am new to javascript and i am not sure how can i use the java script to make it read application variable.


                 

                You can't.  JavaScript is running in the client memory.  The application variable is in the server memory.  These are two different memories on two different computers located in two different places and there is no connection between them.

                 

                You can either send the XML data mingled in the JavaScript you are sending to the client.  This would be the only way to get an "Application" variable into the JavaScript without creating an XML file that is requested separately.  Dan's suggestions of the <cfwddx...> tag or the toScript() function are available to help you do this if you choose to.

                 

                OR

                 

                You can have the JavaScript request the XML from the server which it sounds like you know how to do (" i can read the xml in java script and create the map with info").

                 

                The latter is the choice that makes the most sense to me and is what I do with my CFML generated Google Maps.  It may be interesting to note that the xml file that the JavaScript requests does not have to be a static .xml file.  It can easily be a dynamic .cfm file that returns XML structured data.  Just like other dynamic .cfm files return HTML structured data.  This can be a very powerful combination.