[英]pass variable in javascript to sql server using ajax
我想制作一個Google地圖,該地圖允許人們單擊地圖並將點保存為起點或終點。 單擊一個點后,將顯示一個信息窗口。 我將Google地圖坐標更改為自己定義的坐標。 我已經建立了一個數據庫,其中包含建築物。 也就是說,這樣的數據庫(x Y建築物)(1、2,塔1)(1、3,塔2)
我想傳遞坐標以在sql數據庫中搜索並返回建築物。 並在文本框中顯示建築物名稱。 但是,似乎返回並不成功。 請幫我。 我在互聯網上搜索了很長時間。
storelatlng.php
require_once("Connections/fees0_7548734_cumap.php");
$x = $_GET['x'];
$y = $_GET['y'];
$data = mysql_query("SELECT Bname FROM Coordinate WHERE X=2 AND Y=58") or die(mysql_error());
$info = mysql_fetch_array($data);
$Bname = $info['Bname'];
echo $Bname;
mapfunction.php
var map;
var Bname="";
function storelatlng(){
var y = document.getElementById("Latitude").value;
var x = document.getElementById("Longitude").value
var getVars = "?y="+y+"&x="+x;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var request=new XMLHttpRequest();
}
else
{// code for IE6, IE5
var request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.open('GET','storelatlng.php'+getVars,true);
request.onreadystatechange = function(){
if(request.readyState == 4){
var xmlDoc = request.responseText;
document.getElementById("frmLat").value = xmlDoc;
}
}
request.send(null);
return false;
}
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(22.419161, 114.207559), 17);
GEvent.addListener(map,"click",
function(overlay,latlng){
var setLat = latlng.lat();
var setLon = latlng.lng();
setLat = Math.floor((Math.floor(setLat*100000)-2241187)/20);
setLon = Math.floor((Math.floor(setLon*100000)-11420020)/20 );
//y
document.getElementById("frmLat").value = setLat;
//x
document.getElementById("frmLon").value = setLon;
var inputForm = document.createElement("form");
inputForm.setAttribute("action","");
inputForm.onsubmit = function(){storelatlng();
return false;
};
inputForm.innerHTML = '<fieldset style = "width:200px;">'
+ '<legend> Mark Point </legend>'
+ 'Please choose it '+Bname+' your starting or ending point.'+'<p></p>'
+ '<label><input type="radio" name="choice" value="0" id="choice_s" />Start</label>'
+ '<label><input type="radio" name="choice" value="1" id="choice_e" />End</label>'
+ '<input type="submit" value="Save"/>'
+ '<input type="hidden" id="Longtitude" value="'+setLon+'"/>'
+ '<input type="hidden" id="Latitude" value="'+setLat+'"/>';
map.openInfoWindow(latlng,inputForm);
});
<?php
至少要確保您的函數和函數調用正確完成。 GEvent.addListener
缺少結束括號(匿名函數后面有分號,表示GEvent.addListener
已結束),並且代碼示例結尾處還有一個多余的括號。 初始化似乎也缺少括號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.