AJAX JQuery加载KML层

I'm trying to utilize a KML layer onto Google Maps API 3.0 using a JQuery AJAX request. This is what I have so far (not working).

<script>
 $(document).ready(function(){

 $.ajax({
   url : 'https://blahhhhhhhhhh.com/KML_Placemarks.kml',
   dataType : 'html',
   success : function(data) {
     console.log(data);
     var Google = new google.maps.LatLng(37.42228990140251,-122.0822035425683);
     var mapOptions = {
      zoom: 18,
      center: Google
   }

   var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
   var ctaLayer = new google.maps.KmlLayer({
     //url: 'http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'
     url: data
   });

   ctaLayer.setMap(map);
   console.log(data);

   }
  });                           
 });
</script>

The example from the Google Maps API documentation simply has that cta.kml file assigned to the url piece. What I want to do is substitute that with the result of the AJAX request.

I feel like it's possible because the result of the console.log(data) reads the content it eventually needs.

Thanks!

This is not possible. KmlLayer works by having Google's servers read the KML and render it as tiles (so it needs to be publicly available). If you want to load it locally, you can look at a third party KML parser (like geoxml3 or geoxml-v3) or roll your own to render the data as native Google Maps Javascript API v3 objects, but there will be a performance hit.

This should work (if "data" is valid KML and your KML is not too complex):

<script>
 $(document).ready(function(){

 $.ajax({
   url : 'https://blahhhhhhhhhh.com/KML_Placemarks.kml',
   dataType : 'html',
   success : function(data) {
     console.log(data);
     var Google = new google.maps.LatLng(37.42228990140251,-122.0822035425683);
     var mapOptions = {
      zoom: 18,
      center: Google
   }

   var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
   var geoXml = new geoXML3.parser({
                map: map
            });

   geoXml.parseKmlString(date);

   ctaLayer.setMap(map);
   console.log(data);

   }
  });                           
 });
</script>