views:

511

answers:

1

I pass activerecord data from rails to JavaScript function as JSON using ajax. my request.responseText looks like this

[{"site": {"lng": 55.1443, "lat": 25.0608}},
 {"site": {"lng": 55.1065, "lat": 25.0399}}]

Below is my JavaScript code

var sites=eval('(' + request.responseText + ')');

for (var i = 0 ; i < sites.length ; i++) {
      var site=sites[i].attributes
      var lat=site.lat;
      var lng=site.lng;

but if I alert(site.lat) it's returning undefined. What am I doing wrong here?

+3  A: 
 var site=sites[i].attributes

should be

 var site=sites[i].site
Alexander Gyoshev
Hi Mate, thanks a lot. I was breaking my head over this. Newbie problems :)
You're welcome :) And since you're new to the site - it's customary to mark the answer that helped you achieve your goal ;)
Alexander Gyoshev