How can I return a value from the google engine for jQuery?

After the user enters data on my home page, I want to send the values ​​to the google python script application engine for processing. When the processing of the script is complete, I want it to pass the values ​​back to my home page, which will display the results at the bottom of the page. Since I do not want to reload the whole page, I want to use jquery when the user ends up in submit.

I have 2 questions 1) How to transfer the results to my homepage from python 2) In my $ .ajax call, how do I specify the name of a python script that will handle the processing

jquery code $(function() { $("input#Submit").click(function() { $.ajax({ type: "POST", url: "/", //my python script data: { var1: $("input#var1").val(), var2: $("input#var2").val() }, success: function(returnData){ alert(returnData) } }); }); python script class processInfo(webapp.RequestHandler): var1 = self.request.get("var1") var2 = self.request.get("var2") do some processing here eg var 3 = var1* var2 how do i return var 3 back to the $.ajax call? application = webapp.WSGIApplication( ('/', processInfo), debug = true) 
+4
source share
1 answer

The returnData argument returnData the success function in your Javascript will be passed to the body of the response to the HTTP request. Just write the data you self.response.out.write using self.response.out.write in your handler.

To indicate that the script call is executed in the same way as elsewhere: map the handler in your WSGI application (in your example, it displays as β€œ/”, which you probably do not need) and make sure the script handler is correct displayed in app.yaml. Handling an AJAX call is no different than handling any other standard HTTP request.

+4
source

All Articles