我有一个用于游戏的google maps网络应用程序,用户将单击google map标记,在弹出的窗口中进行选择,然后单击Submit。它使用AJAX用用户选择的信息更新数据库。数据库中已预先加载了标记的名称和GPS坐标。标记也通过XML相应地放置。
提交数据库时,我无法用用户选择的信息来更新数据库中名为 quest 的一行。当前,用户可以选择一个标记并提交一个任务,但是它根本不会更新数据库。我不确定要使用的正确WHERE语句。这是我当前的SQL语句,我正在尝试更新名为 quest 的行。
mysqli_query($con, "UPDATE markers SET quest= '$questName' WHERE markerName = '$markerName'");
这是myMap函数内部的我的downloadURL函数
downloadUrl("call2.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("markerName");
// var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("longg")));
var icon = customLabel[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
这是按下提交按钮时发生的情况。
if (document.getElementById("questType").value ==
"quest1") { //if quest1 is selected upon submission
alert("quest1");
var markerName;
var questName = "Quest 1";
xmlhttp = new XMLHttpRequest(); //Creating the
XMLHttpRequest object
xmlhttp.open("GET", "ajax.php?questName=" + questName
+ "&markerName=" + markerName, true); //Specifying the type of request to the server
xmlhttp.send(); //Sending the request to the server
这是我相关的ajax.php。
<?php
include("connect.php");
require("call.php");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " .
mysqli_connect_error();
} else {
}
$markerName = mysqli_real_escape_string($con,
$_GET['markerName']);
$questName = mysqli_real_escape_string($con,$_GET['questName']);
$lat = mysqli_real_escape_string($con, $_GET['lat']);
$longg = mysqli_real_escape_string($con, $_GET['longg']);
mysqli_query($con, "UPDATE markers SET quest=
'$questName' WHERE markerName = '$markerName'");
mysqli_close($con);
这也是我的相关通话记录。
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
include('connect.php');
$query = "SELECT * FROM markers WHERE 1"; // Select all the rows in the markers table
$result = mysqli_query($con, $query);
if (!$result) {
die('Invalid query: ' . mysqli_error($con));
}
// Iterate through the rows, adding XML nodes for each
while ($row = mysqli_fetch_assoc($result)) {
global $dom, $node, $parnode;
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("markerName",
$row['markerName']);
$newnode->setAttribute("quest", $row['quest']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("longg", $row['longg']);
}
header("Content-type: text/xml");
echo $dom->saveXML();
我没有收到任何错误,但是,当我将鼠标悬停在chrome的“网络”标签中的ajaxphp上时,看起来好像正在获得questName,但markerName仍未定义。