Through map.php I’m sending an ajax request to my php code.I need to store ajax response in javascript variable and later need to print its the variable content in Google maps info window.
How to achieve this…??
** Below is my map.php code**
<html>
<body>
<div id="googleMap" style="width:100%;height:74%;top:8%;"></div>
<script>
function myMap() {
var mapProp= {
center:new google.maps.LatLng(13.029400,77.5639000),
zoom:19,
mapTypeId: google.maps.MapTypeId.HYBRID,
fullscreenControl: true,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
map.setTilt(90);
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(13.029400,77.5639090),
title: 'Inverter-1',
icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png'
});
marker1.setMap(map);
marker1.addListener('click', function() {
$.ajax({
url : "info/inverter1-info.php",
type: 'GET',
success:function(data)
{
if(data){
//Need to store data in a variable and later display in infowindow
alert(data);
}
else{
console.log("Data is empty");
}
},
error: function(xhr) {
alert('Error! Status = ' + xhr.status + " Message = " + xhr.statusText);
}
});
});
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBCihtiN6xfJYUn7mgbMwbGAPWKBYUOBh8&callback=myMap"></script>
</body>
</html>
Below is my php code
<?php
ini_set('display_errors', 1);
$request=curl_request("http://192.168.1.220/cgi-bin/handle_login.tcl","user=admin&pw=admin&submit=Login");
function curl_request($url,$postFields)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,
$postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response= curl_exec($ch);
$sid = substr($response,90,19);
echo "$sid";
$url1 = "http://192.168.1.220/cgi-bin/controller.tcl?sid=$sid&type=inverter&inverter=317602N463";
$url2 = "http://192.168.1.220/cgi-bin/overview.tcl?sid=$sid&menuParentId=3";
$nodes = array($url1, $url2);
$node_count = count($nodes);
$curl_arr = array();
$master = curl_multi_init();
for($i = 0; $i < $node_count; $i++)
{
$url =$nodes[$i];
$curl_arr[$i] = curl_init($url);
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($master, $curl_arr[$i]);
}
do {
curl_multi_exec($master,$running);
} while($running > 0);
for($i = 0; $i < $node_count; $i++)
{
$results = curl_multi_getcontent ( $curl_arr[$i] );
if($i%2 != 0)
{
header('Content-type: html');
echo json_encode($results);
}
}
}
?>