我目前正在嘗試使用AJAX從數據庫中檢索選定的記錄。我有2個文件 - browser.php和getrecord.php。AJAX xmlhttp.open
在browser.php,我使用地理位置javascript來獲得緯度和經度並將其存儲在全局變量:
browser.php
var numlat;//store latitude
var numlong;//store longitude
function loadrecord(numlat,numlong)
{
if(numlat=="" || numlong==""){
document.getElementById("box").innerHTML="";
return;
}
if (window.XMLHttpRequest){
//code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else{
//code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readystate==4 && xmlhttp.status==200){
document.getElementById("box").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getrecord.php?q=numlat&r=numlong", true);
xmlhttp.send();
}
我的主要問題是如何做我發了使用numlat和numlong作爲2參數向服務器請求getrecord.php?我將需要使用它們var numlat和var numlong值在我的數據庫中執行SELECT並將它們顯示在browser.php中。
getrecord.php
$q = $_GET['q'];//i am trying to get the latitude
$r = $_GET['r'];//i am trying to get the longitude
//i will need to use $q and $r to do a SELECT in my database.
對不起,如果這是一個noob問題。
可能重複(http://stackoverflow.com/questions/3304014/javascript-variable-inside-string-without -concatenation-like-php) – Quentin