سؤال

I'm trying to place markers on a google map based on values filed in a mysql db. When loading the xml dynamically using PHP, no markers get placed on the map due to the responseXML.DocumentElement property not getting valued. It works when I load the XML from a static file, just not when dynamically loading from a db.

Here is the page that doesn't work: http://www.thirstygolfer.com/utils/maptest2.html
Here is the page that works: http://www.thirstygolfer.com/utils/maptest1.html

This is the PHP file generating the xml: www.thirstygolfer.com/utils/xmldump3.php

Here is the PHP code from thirstygolfer.com/utils/xmldump3.php (minus the db connection info):

<?php

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node); 

$result=mysql_query("SELECT * FROM Main WHERE State='MA' and FirstLetter='A'");

header("Content-type: text/xml");

while ($row = mysql_fetch_assoc($result)){    

$node = $dom->createElement("marker");   
$newnode = $parnode->appendChild($node);     
$newnode->setAttribute("id",$row['id']);  
$newnode->setAttribute("lat", $row['Lat']);    
$newnode->setAttribute("lng", $row['Lon']);    
} 

echo $dom->saveXML();

?>

Please help!!

هل كانت مفيدة؟

المحلول 2

The headers on the XML are not correct (from web-sniffer.net)

HTTP Response Header
Name    Value   Delim
Status: HTTP/1.1 200 OK
Date:   Fri, 11 Jan 2013 18:38:04 GMT   
P3P:    policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"   
Content-Type:   text/html   
Age:    0   
Connection: close   
Server: YTS/1.19.11:

The Content-Type needs to be "text/xml"

نصائح أخرى

Your generated XML contains blank lines at the top of the output, which will make it invalid XML. This is likely because you have empty lines in included PHP files either before the first <?php or after the last ?>

You may also need to set header('Content-Type: text/xml') so that browsers know what kind of data it is.

This issue is resolved. Thank you for your help. There were 2 issues with my code:

1.) The content type was 'text/html'. I needed to add the following line to my php script:

header("Content-type: text/xml");

2.) The xml file had blank lines at the top. IE handled it, but Chrome and FF had issues with it. I removed the extra lines at the top of the file and it now works in all browsers.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top