If you use Firefox (if you aren't, why not? :-)), get the Firebug extension. Then run that page again, and see if Firebug logs any errors in the javascript and/or net traffic.
But just looking the code at a glance, are you accessing this page via localhost? Most, if not all web browsers employ a same-origin policy that prevents javascript code from manipulating DOM elements sourced from different domains. - Jackie briancomeau wrote: > > Hi there, > > I am having trouble with the 'Hooking to AJAX' tutorial located > https://trac.osgeo.org/mapguide/wiki/CodeSamples/JavaScript/AJAXViewerEventHooking > here. Any help would be much appreciated. I have essentially just copied > the code from the tutorial and inserted my AJAX viewer link, and yet there > does not seem to be any functionality. For example, when I make a > selection, nothing happens, yet an alert should be shown. > > Thanks for the help! > > Here is my code: > <html> > <head> > <title>TEST</title> > <script type="text/javascript"> > > // Map loaded handler > function OnMapInitialized() { > // Map has been initialized now we're off to the races. > alert("Map has been initialized"); > } > > window.onload = function() { > //Timer variable > var timer; > > // This is our "watch" function. What we are doing here is > // repeatedly checking the mapInit value of the Map Frame. When > // mapInit is true, then the map has been loaded. > var watch = function() { > > // What we are doing here is attempting to access the mapInit > // variable of the Map frame. The reason the code is in a > try-catch > // is because chances are that this code access the DOM > // of the map frame before its DOM has been initialized. > try { > var mapFrame = viewerFrame.mapFrame; > if(mapFrame.mapInit) { > > // Remove the timer so this watch function stops executing > clearInterval(timer); > > // Call our custom handler > OnMapInitialized(); > } > } > catch(e) { > } > }; > > // Start the "watching" process. We basically invoke the watch > function > // every 200ms until the map has been loaded. > timer = setInterval(watch, 200); > }; > > //Function variable to store the original OnSelectionChanged > var origOnSelectionChanged = null; > > //Our custom selection handler > function MySelectionHandler() > { > //This is important. We don't want to replace the original function, > rather > //we want to attach our code into the execution sequence. So we call > the original > //function first. > origOnSelectionChanged(); > > //Now our code goes here. For our example, we'll just show the number > of objects selected. > var count = viewerFrame.GetMapFrame().GetSelectedCount(); > alert(count + " features selected"); > } > window.onload = function() { > //Timer variable > var timer; > > // This is our "watch" function. What we are doing here is > // repeatedly checking the mapInit value of the Map Frame. When > // mapInit is true, then the map has been loaded. > var watch = function() { > > // What we are doing here is attempting to access the mapInit > // variable of the Map frame. The reason the code is in a > try-catch > // is because chances are that this code access the DOM > // of the map frame before its DOM has been initialized. > try { > var mapFrame = viewerFrame.mapFrame; > if(mapFrame.mapInit) { > > // Remove the timer so this watch function stops executing > clearInterval(timer); > > // Replace the OnSelectionChanged function with our own > function. > // It is safe to do this now because the DOM for the map > frame is fully initialized. > > // Store old function > origOnSelectionChanged = mapFrame.OnSelectionChanged; > // Now replace with our own. > mapFrame.OnSelectionChanged = MySelectionHandler; > } > } > catch(e) { > } > }; > > // Start the "watching" process. We basically invoke the watch > function > // every 200ms until the map has been loaded. > timer = setInterval(watch, 200); > }; > > </script> > > </head> > <frameset rows="30,*" frameborder="no" framespacing="0"> > <frame id="titleFrame" frameborder="no" marginwidth="0" > marginheight="0" scrolling="no" src="title.html"> > <frame id="viewerFrame" frameborder="no" marginwidth="0" > marginheight="0" scrolling="no" > src="http://localhost:8008/mapguide2009/mapviewerajax/?WEBLAYOUT=Library://Samples/Layouts/BrianSamples.WebLayout&LOCALE=en"> > </frameset> > </html> > -- View this message in context: http://n2.nabble.com/Hooking-to-AJAX%2C-code-problem--tp2940439p2950274.html Sent from the MapGuide Users mailing list archive at Nabble.com. _______________________________________________ mapguide-users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/mapguide-users
