I am doing something similar to what you need in my current project.
I get this kind of zipcode that returns a geojson or null result
My view:
def get_zipcode(request, latitude, longitude):
point = GEOSGeometry('POINT(%s %s)' % (longitude, latitude))
try :
zipcodes = Zipcode.objects.filter(mpoly__contains=point)
return HttpResponse(zipcodes[0].mpoly.geojson, mimetype="application/json")
except :
return HttpResponse(json.dumps(None), mimetype="application/json")
my mimetype - application/json not application/javascript
URL:
url(r'^collision/zipcode/(?P<latitude>(\-|)\d+\.\d+)/(?P<longitude>(\-|)\d+\.\d+)/', 'core.views.get_zipcode', name='collision-zipcode'),
JS, json
$.ajax({
url : '/collision/zipcode/' + latitude + '/' + longitude + '/',
dataType : 'json',
type : 'GET',
success: function(data)
{
var paths = coord_to_paths(data.coordinates);
var polygon = new google.maps.Polygon({
paths : paths,
strokeColor : "#FF7800",
strokeOpacity : 1,
strokeWeight : 2,
fillColor : "#FF7800",
fillOpacity : 0.6
});
polygon.setMap(map);
console.log("adding zipcode polygon");
}
});
, json, dataType "json", JS.
, jquery,
console.log(data);
dev- w/i (chrome/ff , )