duanhaodi4809 2015-06-23 20:23
浏览 50
已采纳

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

I'm trying to read a saved location from data base using JavaScript from xml file my idea is to add markers to this map from the saved locations here is the xml code,is there is something wrong in my method of reading 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

the other code which is not working the map appears but the location inside that xml files are not appearing:

 <!--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-->

</div>
  • 写回答

1条回答 默认 最新

  • douchuza8908 2015-06-23 20:48
    关注

    Sorry,the wrong here is I should call: request.open("GET", "xml.php", false); not request.open("GET", "http://localhost/xml.php", false); the error here is stating the location of the file in the server not the location of it on the computer...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。