• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

reading application varibale from javascript

Guest
May 03, 2010 May 03, 2010

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

333

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 03, 2010 May 03, 2010

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2010 May 03, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 04, 2010 May 04, 2010

Copy link to clipboard

Copied

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.getAttribute("type");
  var cause = markers.getAttribute("cause");
  var mapID = markers.getAttribute("id");
  var reportTime = markers.getAttribute("sTime");
  var estRestore = markers.getAttribute("eTime");
  var LatLng = new google.maps.LatLng(parseFloat(markers.getAttribute("lat")),
                                    parseFloat(markers.getAttribute("lng")));

and so on.....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 04, 2010 May 04, 2010

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation