0

I am facing problem for reading xml file using javascript.

It works fine in other browser but in it its throw the following error.

Microsoft JScript runtime error: 'null' is null or not an object

My code snippet is as below.

  GDownloadUrl("<?php echo $cfg->webroot;?>/G-map/map_xml/<?php echo $_SESSION['xml_file_name'];?>", function(data) {
              var xml = GXml.parse(data);
              var markers = xml.documentElement.getElementsByTagName("marker");

             for (var i = 1; i <=markers.length; i++) 
             {  

                /// Error produce here just for IE  

                    var type=markers[i].getAttribute("type");
                     var name =markers[i].getAttribute("title");

                     var address =markers[i].getAttribute("address");
        //           var link= '<a href="doc_detail/doc_detail-'+ markers[i].getAttribute('id')+'.html" class="doc_url">Read More</a>';
                     var point = new GLatLng(parseFloat(markers[i].getAttribute("latitude")),
                     parseFloat(markers[i].getAttribute("longitude")));

                     var marker = createMarker(point, name, address, type);
                     map.addOverlay(marker);
             }

Thanks in advance

1 Answer 1

1

Your loop is using a 1-based array: I'd be surprised if this was correct...

Try this instead:

for (var i = 0; i < markers.length; i++) 
Sign up to request clarification or add additional context in comments.

6 Comments

thanks a lot, its works for me, can you please explain whats the problem actually?
Arrays in javascript are 0 based. This means that an array with 5 elements (length 5) has elements 0 through 4. Not 1 through 5. This means your condition was an "off by one" error.
Yup, there's not really anything to add to @coderjoe's explanation
Hi Greg, above code is my xml file read code using google api. It works fine in all browser, but in ie7 and ie8 it create a problem with reading xml file, Actually my xml file is updating on certain event and after that event this xml file is read through ajax and data will be displayed in map. Here xml file is updating very fine, but in ie7 an ie8, every time ajax gives the very first response. Means its not reading the latest xml file. Can you please explain what can be the problem, particular for ie7, and ie8..
It sounds like the XML is being cached - add a random number to the URL - for example if you have "google.com/foo.xml" make it "google.com/foo.xml?rnd=" + Math.random()
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.