javascript - click event in google maps and AJAX -


i have map have markers try when user click on marker make ajax request in php file , ajax send json lat/long of marker , lat/long of user in php file file make query in db , return json array geometries of result. when run mozila consol hasnt show error if put alert(ar.latstart); frond of ajax show data. json data

var coords = {'latstart': latpos , 'longstart' : longpos , 'latend' : latitude , 'longend' : longitude}; 

the event of google maps

google.maps.event.addlistener(marker, 'click', function() {     var latitude = this.position.lat();     var longitude = this.position.lng();                 var coords = {'latstart': latpos , 'longstart' : longpos , 'latend' : latitude , 'longend' : longitude};                 getcoords(coords); }); 

the ajax function getcoords is

function getcoords(ar) {         alert(ar.latstart); //the alert show values hasnt have problem          $.ajax({                 url: 'routing.php',                 type: 'get',                 data: ar ,                 cache: false,                 datatype : 'json',                 success: function(rsp){                     alert(json.stringify(rsp)); //show empty alert                 }         }); } 

and php file

if(isset($_get['data'])){     $obj = json_decode($_get['data']);     //some php operation } echo $obj; 

the mozilla not show problem in consol show empty alert of ajax success. please if can 1 me try days cant find whats wrong

because there no key in request named data not work:

 $_get['data'] // because key not in request. 

instead can try send like:

getcoords({"data":coords}); 

and @ php end:

if(isset($_get['data'])){     $obj = json_decode($_get['data']); //some php operation } echo json_encode($obj); /*<---encode , echo.*/ 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -