【发布时间】:2015-07-20 08:33:38
【问题描述】:
我正在使用 Html5 地理定位来获取用户的坐标并通过 Javascript 将它们发送到外部 PHP 文件以反向定位地址:
xhr.open( 'GET', 'utility/fetch.php?lat='+lat+'&lng='+lng, true );
在 fetch.php 上,我正在反向定位街道地址以及我需要解析响应并将其发回的任何内容。
function geo_callback(r){
var result = //parsing r and getting required data
/*
some code here for declaring variables and stuff
*/
//printing the result from database
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
//sending result to another external php to fetch data from database
xmlhttp.open("GET", "utility/coord_to_add.php?result="+result ,true);
xmlhttp.send();
}
现在我的问题是,这是一种有效的方法吗?让我们忽略我只是提供我在这里使用的方法的所有错误处理。另外,我意识到我作为结果返回并在“结果”div 中打印的数据不应用 CSS。
【问题讨论】:
-
是的。关于所有要说的
-
您可能希望 PHP 输出 JSON,这样将来添加更多信息也会更容易,并且 JavaScript 也易于处理。
-
但奇怪的是,css 没有应用,假设我将数据库中的结果回显为: echo "".$someData."";尽管 .customDIV 存在,但没有应用 css
标签: javascript php html geolocation