无法从xml文件javascript读取保存的位置
not able to read saved locations from an xml file javascript
我正试图使用JavaScript从xml文件中读取数据库中保存的位置。我的想法是从保存的位置向该地图添加标记。这是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-->
对不起,这里错了,我应该打电话:request.open("GET","xml.php",false);不请求.open("GET","http://localhost/xml.php",false);这里的错误是说明文件在服务器中的位置,而不是它在计算机上的位置。。。
相关文章:
- 读取一个本地文件,编码为base64,我想给用户一个将结果保存到文件的选项
- 如何用程序读取和解析gruntfile,这样我就可以修改它并再次保存
- 读取文本文件并使用 JavaScript 将内容保存在数组中
- Cookie 保存/读取无法按预期工作
- 在Javascript(Angular)中读取,更改和保存文档
- 离子类型错误:第一次单击保存按钮时无法读取未定义的属性“标题”
- 当我在 JavaScript 中保存/读取 csv 文件时,如何使用第二张工作表
- 从特定网页读取文本,并使用javascript将其保存在变量中
- JavaScript-从文件中读取URL并将其保存为数组中的元素
- Cordova -如何保存和读取JSON对象从本地存储
- 如何使用node-imap读取和保存附件
- 我怎么能读取数组我保存在一个cookie与jquery.cookie
- Javascript:保存不使用PHP读取GET的方式
- 读取文本文件上下文,而不保存在服务器上- Asp经典
- localStorage保存对象,但不能读取其内容
- 当试图将表单元素保存到mongoDB时,无法读取未定义错误的属性
- jQuery读取XML并保存数据以便在另一个插件中访问
- 读取一个json文件并将数据(作为json)保存在列表中
- localStorage UIWebView iPhone/iPad保存或读取不起作用.有时
- 无法从xml文件javascript读取保存的位置