Ajax Form submittion in Google App Engine with jQuery
- by user271785
could not figure out why it is not working:
i need to send request to server, generate some fragment of html in python with meanCal method, and then want that fragment embedded into submitting html file using calculation method and dynamically shows in dyContent div. all the processes are done by single click on submit button in a form.
any suggestions??? thanks in advance.
the submitting html:
<div id="dyContent" style="height: 200px;">
waiting for user...
{{ mgs }}
</div>
<div id="leturetext">
<form id="mean" method="post" action="/calculation">
<select name="meanselect">
<option value=10>example</option>
<option value=11>exercise</option>
</select>
<input type="button" name="btnMean" value="Check Results" />
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
//$("#btnMean").live("click", function() {
$("#mean").submit(function(){
$.ajax({
type: "POST",
cache: false,
url: "/meanCal",
success: function(html) {
$("#dyContent").html(html);
}
});
return false;
});
});
</script>
python:
class MainHandler(webapp.RequestHandler):
def get(self):
path = self.request.path
if doRender(self, path):
return
doRender(self,'index.htm')
class calculationHandler(webapp.RequestHandler):
def post(self):
doRender(self, 'Diagnostic_stats.htm',
{'mgs' : "refreshed.", })
def get(self):
doRender(self, 'Diagnostic_stats.htm')
class meanHandler(webapp.RequestHandler):
def get(self):
global GL
index = self.request.get('meanselect'.value)
if (index == 10):
allData = GL.exampleData
dataString = ','.join(map(str, allData))
dataMean = (str)(stats.lmean(allData))
doRender(self, 'Result.htm',
{
'dataIn' : dataString,
'MEAN' : "Example Mean is: " + dataMean,
})
return
else:
allData = GL.exerciseData
dataString = ','.join(map(str, allData))
dataMean = (str)(stats.lmean(allData))
doRender(self, 'Result.htm',
{
'dataIn' : dataString,
'MEAN' : "Exercise Mean is: " + dataMean,
})
def main():
global GL
GL = GlobalVariables()
application = webapp.WSGIApplication(
[('/calculation', calculationHandler),
('/meanCal', meanHandler),
('.*', MainHandler),
],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()