I have created a php page that makes use of Google Javascript APIs. I am trying to use Ajax to populate the info windows of the markers dynamically, but get a permission denied error on the xdr.open line. I have checked the other posts relating to similar errors, and tried different changes, but still the same error.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type=text/javascript>
var marker;
var map;
var xdr;
function loader()
{
alert("XDR onload");
alert("Got: " + xdr.responseText);
}
function Info(pmarker)
{
google.maps.event.addListener(pmarker, 'mouseover', function()
{
if (window.XDomainRequest)
{
xdr = new XDomainRequest();
if(xdr)
{
document.write('1');
xdr.open("GET", "http://localhost/GMap/GroovyCaller.php?Node=Host1");
xdr.send();
document.write('2');
xdr.onload = loader;
}
else
{
document.write('3');
alert('Failed to create');
}
}
else
{
document.write('4');
alert('XDR does not exist');
}
});
}
function createMarker() {
var myLatlng = new google.maps.LatLng(-34.397, 150.644);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
Info(marker);
}
function initialize()
{
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions =
{
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
createMarker();
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
Is
GroovyCaller.php
returning the http headerAccess-Control-Allow-Origin
? From http://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx:Your server must know about your client to accept a cross domain connection. You can start with
Access-Control-Allow-Origin: *
to get it working, and then narrow it down.