用于Google Maps InfoWindow的PHP XML [英] PHP XML for Google Maps InfoWindow
问题描述
boxText.innerHTML =< div class ='mapname'> +'< a href =<?php echo get_permalink($ post_id);?>>'+ name +'< / a> +< / div>< i> + listtype +< / i>< br /> +地址+< br /> +手机;
谢谢!
这是一个完整的PHP-Javascript AJAX示例。只需保存名为
myServerScript.php的文件并将浏览器指向它。 PHP打印javascript,它通过AJAX调用相同的PHP脚本,PHP响应并且javascript处理响应。
<?...?>
<
if(isset($ _ GET ['msg'])){
printalert('AJAX response from PHP - Javascript said:。$ _GET ['msg']。 );
其他{
print<<< qq
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // ENhttp ://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< title> AJAX示例:(by Marcelo)< / title>
< script src =http://maps.google.com/maps/api/js?sensor=false>< / script>
< script>
//抱歉,我无法打字输入google.maps。每次。 ;-)
var G = google.maps;
var zoom = 4;
var centerPoint = new G.LatLng(40.178873,-96.767578);
var container;
var map;
函数ajaxLoad(url,callback,plain){
var http_request = false;
if(window.XMLHttpRequest){// Mozilla,Safari,...
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType& plain){
http_request.overrideMimeType('text / plain');
} else if(window.ActiveXObject){// IE
try {
http_request = new ActiveXObject(Msxml2.XMLHTTP);
catch(e){
try {
http_request = new ActiveXObject(Microsoft.XMLHTTP); (!http_request){
alert('放弃:(无法创建一个XMLHTTP实例');
} catch(e){}
}
}
;
返回false;
}
http_request.onreadystatechange = function(){
if(http_request.readyState == 4){
if(http_request.status == 200 ){
eval(callback(http_request));
}
else {
alert('Request Failed:'+ http_request.status);
}
}
};
http_request.open('GET',url,true);
http_request.send(null);
}
var url =myServerScript .php?msg = hello from javascrpt;
ajaxLoad(url,parseResults,true);
函数parseResults(req){
var text = req。 responseText;
eval(text);
}
函数load(){
container = document.getElementById('mapDiv');
var myOptions = {
zoom:zoom,
center:centerPoint,
mapTypeId:G.MapTypeId.ROADMAP,
rotateControl:true,
keyboardShortcuts:false
}
map = new G.Map(container,myOptions);
google.maps.event.addListener(map,'click',function(mev){
var url =myServerScript.php?msg =+ mev.latLng;
ajaxLoad(url ,parseResults,true);
});
}
window.onload = load;
< / script>
< / head>
< body>
来自PHP的你好。
< h2>点击地图将纬度/经度发送到PHP< / h2>
< div id =mapDivstyle =width:800px; height:450px;>< / div>
< / body>
< / html>
qq;
}
?>
What I'm trying to do is to get the following from my Google maps. I'm aware with JavaScript that it's client side and not server side like PHP so it is loaded before the JS is even ran. The problem is if I were to call the column post_id strictly through PHP -> XML -> JS into the PHP it wouldn't load a link. Is there a way to do this with strictly just PHP and have it pull the locations post_id from the markers table for each of the location markers on the map? I've also read that it is possible with AJAX but I don't have alot of knowledge about AJAX.
boxText.innerHTML = "<div class='mapname'>" + '<a href="<?php echo get_permalink( $post_id ); ?>">' + name + '</a>' + "</div><i>" + listtype + "</i> <br/>" + address + "<br/>" + phone;
Thanks!
Here's a complete PHP-Javascript AJAX example. Just save the file with the name "myServerScript.php" and point your browser to it. PHP prints javascript which calls the same PHP script via AJAX, PHP responds and javascript processes the response.
Make sure your PHP installation is configured to accept the short delimiters <?...?>
<?
if(isset($_GET['msg'])){
print "alert('AJAX response from PHP - Javascript said:". $_GET['msg']."')";
}
else{
print <<<qq
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX Example: (by Marcelo)</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
// Sorry, I can't be bothered typing "google.maps." every time. ;-)
var G = google.maps;
var zoom = 4;
var centerPoint = new G.LatLng(40.178873, -96.767578);
var container;
var map;
function ajaxLoad(url,callback,plain) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType && plain) {
http_request.overrideMimeType('text/plain');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
eval(callback(http_request));
}
else {
alert('Request Failed: ' + http_request.status);
}
}
};
http_request.open('GET', url, true);
http_request.send(null);
}
var url = "myServerScript.php?msg=hello from javascrpt";
ajaxLoad(url, parseResults, true);
function parseResults(req){
var text = req.responseText;
eval(text);
}
function load() {
container = document.getElementById('mapDiv');
var myOptions = {
zoom: zoom,
center: centerPoint,
mapTypeId: G.MapTypeId.ROADMAP,
rotateControl: true,
keyboardShortcuts:false
}
map = new G.Map(container, myOptions);
google.maps.event.addListener(map,'click',function(mev){
var url = "myServerScript.php?msg="+mev.latLng;
ajaxLoad(url, parseResults, true);
});
}
window.onload = load;
</script>
</head>
<body>
Hello from PHP.
<h2>Click on the map to send the lat/lon to PHP</h2>
<div id="mapDiv" style="width: 800px; height: 450px;"></div>
</body>
</html>
qq;
}
?>
这篇关于用于Google Maps InfoWindow的PHP XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!