I'm using Ajax $.post() to post the content of a form to my controller in google app engine. The form basically is trying to find lat/lng using html5 geolocation and user input.
<form method="post" id="simple-form" action="/search">
<div>
<input type="text" placeholder="Keyword" name="searchQuery" id="searchQuery">
<input type="button" id="simple-submit-button">
</div> </form>
Trying to find geolocation
$('#simple-submit-button').click(function () {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
})
function onSuccess(position) {
document.getElementById('Latitude').value = position.coords.latitude;
document.getElementById('Longitude').value = position.coords.longitude;
var x = document.getElementById('Latitude').value;
if (x != undefined || x != null) {
submitform();
}
}
Using jquery $.post() to post the content to a method and render another page.
function submitform() {
var where = $("#simple-firm").attr("action");
var fi = $("#Latitude").val();
var fj = $("#Longitude").val();
var gk = $("#searchQuery").val();
var what = {Latitude: fi, Longitude: fj, searchQuery: gk};
$.post(where, what, handleResponse, "json");
}
Following is my router.py
from webapp2 import WSGIApplication
from webapp2 import Route
app = WSGIApplication([
Route('/search', handler='app.serp.Search'),
}
and my method
class Search():
def get(self):
self.redirect('/')
def post(self):
query_name = self.request.get('searchQuery')
lat = float(self.request.get('Latitude'))
lng = float(self.request.get('Longitude'))
print query_name,lat, lng
#self.response.out.write('<html><body>You wrote:<pre>')
self.render('serp/serp.html')
Although I can see in my terminal that the values of query_name, lat, lng from the are being printed, but neither the self.render nor self.response is displayed. I basically want to render another page called serp.html. What is going wrong here. How to fix it.