无法从xml文件中读取保存的位置javascript

时间:2015-06-23 20:23:04

标签: javascript php xml

我正在尝试使用来自xml文件的JavaScript从数据库中读取保存的位置我的想法是从保存的位置向此地图添加标记这里是xml代码,我的读取xml的方法是否有问题 - :

<?php 
$conn=mysqli_connect("localhost", "thecode007", "007","offers") or die(mysql_error());

$query = "SELECT BLocation FROM Branches";
$result = mysqli_query($conn,$query) or die(mysql_error());

 $doc = new DomDocument('1.0');
$node = $doc->createElement("markers");
$parnode = $doc->appendChild($node);

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

while($row = mysqli_fetch_array($result))
{
$node = $doc->createElement("marker");
$newnode = $parnode->appendChild($node);
$loc=explode(",",$row[0]);
$newnode->setAttribute("lat", $loc[0]);
$newnode->setAttribute("lon",$loc[1]);
}
 
print $doc->saveXML();

?>
//this code is working

显示其他未运行地图的代码,但xml文件中的位置未显示:

 <!--the code up is the map code which is displayed well the problem is downhere-->
   	var marker = new google.maps.Marker({position:latlon1,map:map,title:" here!"});
	var request = new XMLHttpRequest();
request.open("GET", "http://localhost/xml.php", false);
request.send();
var xml = request.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
 var lan2=markers[i].getAttribute("lat");
 var lon2=markers[i].getAttribute("lon");
 var latlon2= new google.maps.LatLng(lan2,lon2);
 marker = new google.maps.Marker({position:latlon2,map:map,title:" here!"});
}
<!--the rest is working-->

1 个答案:

答案 0 :(得分:0)

对不起,这里错了我应该致电: request.open(“GET”,“xml.php”,false); 不是request.open(“GET”,“http://localhost/xml.php”,false); 这里的错误是说明服务器中文件的位置而不是计算机上它的位置......