Reputation: 2904
So I have this html/js trying to test an ajax post
<html>
<head>
<script src="js/jquery-1.8.2.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
document.write("booo");
var data = {"lat":5};
$.ajax({
type: "POST",
url: "/geo",
data: data,
});
});
var data = {"lat":5};
$.ajax({
type: "POST",
url: "/geo",
data: data,
});
</script>
</head>
<body>
<form method="post">
<input name="lat" type="text">
<input name="lon" type="text">
<input type="submit">
</form>
</body>
</html>
Right now I'm just trying to post data, pick it up in python and write it back/store it in db but nothing is happening from my ajax post function. Here's my python,
class GeoHandler(Handler):
def get(self):
self.render("geo.html")
def post(self):
lat = self.request.get("lat")
lon = self.request.get("lon")
self.write(lat)
loc = models.LocModel(coords = db.GeoPt(lat,lon), hm = str(lat).join(str(lon)))
loc.put()
My url handler is
('/geo', GeoHandler),
Eventually i'm trying to use javascript to capture location data of my users and map it... but app engine/webapp2 only likes to grab the ipv6 of the client and there's no way to get the location data of an ipv5 but there are html5/js solns for geo data.. but i can't even post basic data to the server
Upvotes: 0
Views: 1116
Reputation: 21835
You are not including the "lon"
in the data. Something like this:
var data = {"lat": 5, "lon": 6}
You might also want to take a look n the Request Headers and more specifically on X-AppEngine-CityLatLong
. It's a city level and of course it depends on your app.
Upvotes: 1