title: How to do an Ajax GET request to get data from rails and pass it to javascript(google maps)?
body: <p>I have a model Locations with two columns latitude and longitude. I want to find a way where I can get the list of locations and pass them to google maps using Ajax and javascript. So far my code is as follows:</p>
  
  <p>map.js:</p>
  
  <pre><code>function initialize() 
  {   
      var map;
      var latlng = new google.maps.LatLng(37.09, -95.71);
      var options = {
      zoom: 5, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      disableDefaultUI: true,
      disableDoubleClickZoom: true,
      noClear: true,
      navigationControl: true,
      navigationControlOptions: {
          position: google.maps.ControlPosition.TOP_RIGHT
      }
      };
     map = new google.maps.Map(document.getElementById('map'), options);
  
     var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title: 'Click me', 
      });
  }
  </code></pre>
  
  <p>locations_controller.rb</p>
  
  <pre><code>def show
      @location = Location.find(params[:id])
  
      respond_to do |format|
        format.html # show.html.erb
        format.json { render json: @location }
      end
    end
  </code></pre>
  
  <p>Page displaying the map:</p>
  
  <pre><code>&lt;div id="map" onload="initialize();"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>SO now I want to find a way to make an AJAX request from map.js so I can get the locations from the Location model and pass it to the marker object so that when a map is loading all the locations pre-existing in the database are passed to marker and those markers appear.</p>
  
  <p>Thank you.</p>